简体   繁体   English

正则表达式以逗号分隔,但不在方括号和方括号中

[英]Regex split with comma but not in Square Brackets and not in Brackets

i have this string 我有这串

StudentInfo[id] as stu_id, StudentInfo[ssn] as stu_ssn, verylong.library.path.ScoreInfo[min_points, max_points] as sinfo, left_join((id),(customer_id)), reference.dilino[(greed,greed)], reference.dilino2[dilino], reference.dilino3[reference.dilino4[(kaktus,kaktus2)],reference.dilino5[(kaktus3,kaktus4)]], reference.dilino6[reference.dilino4[(kaktus,kaktus2),dilino]

and i want split to this 我想分开

StudentInfo[id] as stu_id
StudentInfo[ssn] as stu_ssn
verylong.library.path.ScoreInfo[min_points, max_points] as sinfo
left_join((id),(customer_id))
reference.dilino[(greed,greed)]
reference.dilino2[dilino]
reference.dilino3[reference.dilino4[(kaktus,kaktus2)]
reference.dilino5[(kaktus3,kaktus4)]]
reference.dilino6[reference.dilino4[(kaktus,kaktus2),dilino]

i have now this regex 我现在有这个正则表达式

/,(?=[^\]]*(?:\[)|[^\)]*(?:\()|$)/gm 

but it's not good :( can you help me? 但这不是很好:(您能帮我吗?

(?![^)(]*\([^)(]*?\)\)),(?![^\[]*\])

Try this.See demo. 试试看。看演示。

http://regex101.com/r/lS5tT3/8 http://regex101.com/r/lS5tT3/8

您可以在此处使用正则表达式: ,(?=[\\s\\w](?!\\w+[\\)\\]])) 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM