Regex to pick characters outside of pair of quotes

前端 未结 6 1443
广开言路
广开言路 2020-11-22 00:29

I would like to find a regex that will pick out all commas that fall outside quote sets.

For example:

\'foo\' => \'bar\',
\'foofoo\' => \'bar,         


        
6条回答
  •  囚心锁ツ
    2020-11-22 00:59

    Try this regular expression:

    (?:"(?:[^\\"]+|\\(?:\\\\)*[\\"])*"|'(?:[^\\']+|\\(?:\\\\)*[\\'])*')\s*=>\s*(?:"(?:[^\\"]+|\\(?:\\\\)*[\\"])*"|'(?:[^\\']+|\\(?:\\\\)*[\\'])*')\s*,
    

    This does also allow strings like “'foo\'bar' => 'bar\\',”.

提交回复
热议问题