给定以下字符串:
var s = "my [first] ga[m]e and [abc]de]\nThe [Game]"
我使用哪个正则表达式来匹配:
0 - [first]
1 - [abc]de]
2 - [Game]
我试过 var pattern2 = new Regex(@"\W\[.*?\]\W"); 但它没有找到 [Game]
我还希望能够匹配“[my] gamers\t[pro]”
0 - [my]
1 - [pro]
请您参考如下方法:
\[[^\[]{2,}\]
解释:
\[ # Match a [
[^\[]{2,} # Match two or more non-[ characters
\] # Match ]
查看 RegExr .
