开发者

How to escape a C# regular expression in the correct way?

This is my regex in plain form:

<tr>[\s]+?<td class="filePathActiv"[\w\W]+?<div class="Overflow">[\s]*?(?<name>[\w\W]+?)&开发者_JS百科;nbsp[\w\W]+?\(wygasa (?<wygasa>[\d\s\-\:\s]+)\)[\w\W]+?class="fileDown"[\w\W]+?<a href="(?<address>[\w\W]+?)">[\w\W]+?<td width="[\d]+?">(?<sizeMB>[\d\.]+?) MB</td>[\w\W]+?<input [\w\W]+? name="(?<path>[\w\W]+?)" [\w\W]+? value="(?<value>[\w\W]+?)"[\w\W]+?/>

How should I escape this regex? I tried like that but it's not working:

new Regex("<tr>[\\s]+?<td class=\"filePathActiv\"[\\w\\W]+?<div class=\"Overflow\">[\\s]*?(?<name>[\\w\\W]+?)&nbsp[\\w\\W]+?\\(wygasa (?<date>[\\d\\s\\-\\:\\s]+)\\)[\\w\\W]+?class=\"fileDown\"[\\w\\W]+?<a href=\"(?<address>[\\w\\W]+?)\">[\\w\\W]+?<td width=\"[\\d]+?\">(?<sizeMB>[\\d\\.]+?) MB</td>[\\w\\W]+?<input [\\w\\W]+? name=\"(?<path>[\\w\\W]+?)\" [\\w\\W]+? value=\"(?<value>[\\w\\W]+?)\"[\\w\\W]+?/>", RegexOptions.IgnoreCase);


You should put it in a @"..." string.
Then, all you need to do is replace every " with "".


I think you should use Regex.Escape() method.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜