@"\[ [~\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);
精彩评论