如何提取括号(圆括号)之间的文本?我有一根绳子User name (sales)我想提取括号中的文字,我该怎么做呢?我怀疑子字符串,但我不知道如何阅读直到结束括号,长度的文本将有所不同。
3 回答
湖上湖
TA贡献2003条经验 获得超2个赞
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 关注
- 910 浏览
添加回答
举报
0/150
提交
取消