Split string by comma if not within square brackets or parentheses

后端 未结 1 1801
借酒劲吻你
借酒劲吻你 2021-01-07 09:29

I have a long string, and I want to set it to an array by splitting it by the comma as long as the comma is not within square brackets or parentheses. I\'ve tried a couple o

相关标签:
1条回答
  • 2021-01-07 09:56

    You can use the following regex with global flag.

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

    Here is a demo. It is inspired by https://stackoverflow.com/a/9030062/1630604.

    0 讨论(0)
提交回复
热议问题