鑑於以下〜應變:正則表達式開始用[和結尾] - 匹配的話只
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]
可能的重複:http://stackoverflow.com/questions/546433/regular-expression-to-match-outer-brackets進一步閱讀:http://stackoverflow.com/questions/524548/regular-expression -to-detect-sem-colon-terminated-c-for-while-loops/524624#524624 – hometoast
我不認爲它是重複的。他不在尋找平衡括號('[abc] de]'不平衡),他正在尋找位於單詞邊界的括號。 – Barmar