Parse commas not surrounded by brackets

我的梦境 提交于 2019-12-20 03:53:12

问题


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

回答1:


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




回答2:


Try this :

"[a-z0-9]*(\\[[a-z0-9\\[\\],]+\\])*"


来源:https://stackoverflow.com/questions/12305182/parse-commas-not-surrounded-by-brackets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!