繁体   English   中英

c# regex - 之前的所有空格<pre>

[英]c# regex - all white space before <pre>

你能帮我整理一些正则表达式吗?

我想要<pre>之前的所有空格

public Regex BeforePre = new Regex(@"^.*?(?=<pre>)", RegexOptions.Compiled);

这将选择<pre>之前的所有内容,而不仅仅是空格。 我只想选择空格。

使用http://regexstorm.net/tester

Pattern: ^.*?(?=<pre>)

Input: dewjdoiejw; test <pre>frfef</pre>

我相信它是\\s但我无法让它工作。

我也希望它可以跨多行工作,例如:

Input: dewjdoiejw; test 

<pre>frfef</pre>

如果您需要更多信息,请告诉我。

更新

见.... http://goo.gl/8mX5c3

我想删除<pre>之前的所有空白和制表符

我只想考虑<pre>之前的所有文本,并从该文本中删除所有空格/制表符。

更新

<div>
    <div>
       some text

        <div>some text</div>     
    </div>

    <div>some text</div>   

</div>

<pre>
   <div>
      <div>some text

      <div>some text</div>
    </div>

   <div>some text</div>

   </div>
</pre>

<div><div>some text<div>some text</div></div><div>some text</div></div>
<pre>
   <div>
      <div>some text

      <div>some text</div>
    </div>

   <div>some text</div>

   </div>
</pre>

好的:可以只使用一个正则表达式:

(?s)([\\s\\r\\n]*(?<value></?.*?>)[\\s\\r\\n]*|(?<=</?.*?>)[\\s\\r\\n]*(?<value>.*?)[\\s\\r\\n]*(?=</?.*?>))(?=.*\\n<pre>)

很短 - 我知道:-)

代码演示

对不起 - 但不要问我解释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM