Parse parameters and values of smarty-like string in PHP

前端 未结 1 1192
清酒与你
清酒与你 2021-01-27 01:01

I\'m trying to create simmiliar parser like smarty. For very small parts of code, and don\'t want to implement huge smarty-like parser.

What I came up with is: (?:

相关标签:
1条回答
  • 2021-01-27 01:30

    You need to use branch reset groups:

    (?|([a-zA-Z0-9]+)=(?|([^\v '"]+)|"(.*?)"|'(.*?)')|([a-zA-Z0-9]+))
      ^                 ^
    

    See the regex demo.

    From the reference:

    Alternatives inside a branch reset group share the same capturing groups. The syntax is (?|regex) where (?| opens the group and regex is any regular expression. If you don't use any alternation or capturing groups inside the branch reset group, then its special function doesn't come into play. It then acts as a non-capturing group.

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