解析不被括号括起来的逗号括号、逗号、不被

2023-09-04 01:15:01 作者:举悲到凌尘ゅ

输入是一个逗号分隔的字段列表。

下面是一个例子。

  TNA,性能,MA [性能,3,价格
 

问题是,一些字段都在方括号中指定参数,这些参数也有逗号。

正则表达式是什么我能使用,打破这样的字符串的逗号,只有当他们括号内。我想最终的结果是

  TNA
性能
马[演出,3]
价格
 
初一数学精选10大易错题型 例题解析

解决方案

这是你所需要的。

 (小于?!?\ [\ W,] *),
 

如果是嵌套的括号内支架,使用这个,因为上面会在这情况下也会失败。

 (小于?!\ [?[\ W,] *)(?!?[\ W,] * \])
 

这里

The input is a comma-separated list of fields.

Here is an example.

tna,performance,ma[performance,3],price

The issue is that some of the "fields" have parameters specified in square brackets and those parameters also have commas.

What RegEx could I use to break a string like that on commas, only when they are outside of brackets. I want the end result to be

tna
performance
ma[performance,3]
price

解决方案

This is what you need

(?<!\[[\w,]*?),

If brackets are nested within brackets, use this because the above would fail in that scenario..

(?<!\[[\w,]*?),(?![\w,]*?\])

works here