解析不被括号括起来的逗号 [英] Parse commas not surrounded by brackets
本文介绍了解析不被括号括起来的逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
输入是一个逗号分隔的字段列表。
下面是一个例子。
TNA,性能,MA [性能,3,价格
问题是,一些字段都在方括号中指定参数,这些参数也有逗号。
正则表达式是什么我能使用,打破这样的字符串的逗号,只有当他们括号内。我想最终的结果是
TNA
性能
马[演出,3]
价格
解决方案
这是你所需要的。
(小于?!?\ [\ 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
这篇关于解析不被括号括起来的逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文