开发者

Why does this .net regex not work?

@"\[ [~\w]+ \]"  

Why does this regular expression not work to find [~dp0] in the string "开发者_如何学Pythonblah blah dummy text [~dp0]"


Because of the spaces. It should be \[[~\w]+\] or use the option IgnorePatternWhiteSpace.


Yeah... It's the spaces.

@"\[[~\w]+\]" 

If you want to ignore the spaces in the pattern, you can use RegexOptions.IgnorePatternWhitespace:

Regex.Match ("blah blah dummy text[~p0]". @"\[ [~\w]+ \]", RegexOptions.IgnorePatternWhitespace);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜