简体   繁体   English

正则表达式命名捕获组时出错

[英]Error while Regex named capturing groups

For one of my application I'm trying to read test from <textarea> tag. 对于我的一个应用程序,我试图从<textarea>标签读取测试。 Below mentioned pattern worked perfectly before, in Visual studio 2010. But in Visual studio 2013 it returns error "Specified argument was out of the range of valid values. Parameter name: i" 在Visual Studio 2010中,下面提到的模式工作得很好。但是在Visual Studio 2013中,它返回错误“指定的参数超出了有效值的范围。参数名称:i”

My regex pattern string exp = @"<textarea[^>]*id=['""]objCodePress_QB_Query['""].*?>(?<xtract>(.*?))</textarea>"; 我的正则表达式模式string exp = @"<textarea[^>]*id=['""]objCodePress_QB_Query['""].*?>(?<xtract>(.*?))</textarea>";

and string sample that I'm looking is 和我正在寻找的字符串样本

<textarea id="objCodePress_QB_Query" name="objCodePress_QB_Query" style="width:100%;" rows=20 class="codepress sql">Hello this is a test</textarea>

Is there any update in regex for new version or how I fix this ? regex是否有新版本的更新或我如何解决这个问题?

It is clear that the issue you have is related to whitespace. 很明显,你遇到的问题与空白有关。

When you declare the Regex object, use RegexOptions.Singleline to force the . 声明Regex对象时,请使用RegexOptions.Singleline强制执行. to match any characters including a newline. 匹配任何字符,包括换行符。

Another solution is to add (?s) right at the beginning of your pattern. 另一种解决方案是在模式的开头添加(?s)

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

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