正则表达式用逗号分隔,但不在Square Brackets而不是Brackets中

时间:2014-09-23 06:48:33

标签: javascript regex split

我有这个字符串

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]

我希望拆分为

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]

我现在有这个正则表达式

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

但它并不好:(你能帮帮我吗?

2 个答案:

答案 0 :(得分:2)

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

试试这个。看看演示。

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

答案 1 :(得分:-1)

你可以使用这样的正则表达式:,(?=[\s\w](?!\w+[\)\]])) demo here