Regex to parse define() contents, possible?

前端 未结 5 1939
北海茫月
北海茫月 2021-01-13 11:06

I am very new to regex, and this is way too advanced for me. So I am asking the experts over here.

Problem I would like to retrieve the constants /

5条回答
  •  天命终不由人
    2021-01-13 11:10

    Not every problem with text should be solved with a regexp, so I'd suggest you state what you want to achieve and not how.

    So, instead of using php's parser which is not really useful, or instead of using a completely undebuggable regexp, why not write a simple parser?

    Output:

    array(3) {
      ["nam'e"]=>
      string(7) "va\'lue"
      ["na\me2"]=>
      string(7) "value'2"
      ["a"]=>
      string(1) "b"
    }
    

提交回复
热议问题