开发者

Why does this .net regex not work?

开发者 https://www.devze.com 2023-03-15 15:17 出处:网络
@\"\\[ [~\\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
@"\[ [~\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

精彩评论

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