繁体   English   中英

正则表达式不起作用

[英]Regex doesn't work

大家好,我有下一条文字:

</form>onclick="g(null,null,'.htaccess','touch')">Touch</a> <br><br><pre class=ml1>
DirectoryIndex index.php
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
</pre></div>

我尝试使用以下命令解析<pre class=ml1></pre></div>的所有内容:-

string con = Regex.Match(content, @"<br><br><pre class=ml1>(.*?)</pre></div>", RegexOptions.Multiline).Groups[1].Value;`

但这是行不通的。 为什么?

你需要

RegexOptions.Singleline

所以. 匹配每个字符, 包括换行符。

您不需要RegexOptions.Multiline因为您没有使用^$ (多行模式使它们匹配行的开头和结尾,而不是输入字符串的开头和结尾。)

您的代码唯一的问题是您使用过Regex.MultiLine,应该使用Regex.SingleLine。

string con = Regex.Match(content, "<br><br><pre class=ml1>(.*?)</pre></div>", RegexOptions.Singleline).Groups[1].Value;

RegexOptions.MultiLine

多行模式。 更改^和$的含义,以便它们分别在任何行的开头和结尾匹配,而不仅仅是整个字符串的开头和结尾。

RegexOptions.SingleLine

指定单行模式。 更改点(。)的含义,使其匹配每个字符(而不是\\ n以外的每个字符)。

暂无
暂无

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

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