[英]How to Split String at “,” with Regex
String: 串:
"ab, ac, Convert(ab,ac), test"
I want this stringArray: 我想要这个stringArray:
ab
ac
Convert(ab,ac)
test
,\s*(?![^(]*\))
Try this.Replace by \\n
.See demo. 试试这个。用
\\n
代替。请参阅演示。
https://regex101.com/r/nL5yL3/28 https://regex101.com/r/nL5yL3/28
This will work on inputs like ab, ac, Convert(ab,ac),test,bc,mc,
too 这也将适用于
ab, ac, Convert(ab,ac),test,bc,mc,
Just split your input acccording to ,\\s+
or , +
regexes. 只需根据
,\\s+
或, +
表达式分割输入即可。 \\s+
matches one or more space characters. \\s+
匹配一个或多个空格字符。
string value = "ab, ac, Convert(ab,ac), test";
string[] lines = Regex.Split(value, @", +");
foreach (string line in lines) {
Console.WriteLine(line);
}
Output: 输出:
ab
ac
Convert(ab,ac)
test
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.