如何提取括號(圓括號)之間的文本?我有一根繩子User name (sales)我想提取括號中的文字,我該怎么做呢?我懷疑子字符串,但我不知道如何閱讀直到結(jié)束括號,長度的文本將有所不同。
3 回答

森欄
TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超5個(gè)贊
Regex.Match("User name (sales)", @"\(([^)]*)\)").Groups[1].Value
\( # Escaped parenthesis, means "starts with a '(' character" ( # Parentheses in a regex mean "put (capture) the stuff # in between into the Groups array" [^)] # Any character that is not a ')' character * # Zero or more occurrences of the aforementioned "non ')' char" ) # Close the capturing group\) # "Ends with a ')' character"
- 3 回答
- 0 關(guān)注
- 348 瀏覽
添加回答
舉報(bào)
0/150
提交
取消