[英]C# regular expression match
I would like to have a Regex which will match a separating comma phrases of equal amount of opening and closing brackets of the same type between a comma.我想要一个正则表达式,它将匹配逗号之间相同类型的相同数量的左括号和右括号的分隔逗号短语。
for example...例如...
{abc} (def), [ghi], (jkl, mno)
-----------------------------
the match should be:
{abc} (def)
[ghi]
(jkl, mno)
I'm working with C# .Net我正在使用 C# .Net
thanks for advance!感谢提前!
If there are no nested brackets, you could use:如果没有嵌套括号,您可以使用:
((?:\{[^}]*\}|\([^)]*\)|\[[^\]]*\])\s*)+
string test = "{abc} (def), [ghi], (jkl, mno)";
string pattern = @"((?:\{[^}]*\}|\([^)]*\)|\[[^\]]*\])\s*)+";
foreach (Match m in Regex.Matches(test, pattern))
Console.WriteLine(m.Value);
This prints:这打印:
{abc} (def)
[ghi]
(jkl, mno)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.