regex not matching due to repeated capturing group rather than capturing a repeated group

后端 未结 3 498
灰色年华
灰色年华 2021-01-14 22:31

I have the following regexp:

/(?:[\\[\\{]*)(?:([A-G\\-][^A-G\\]\\}]*)+)(?:[\\]\\}]*)/

with the following expression:

{A\'\'         


        
3条回答
  •  清酒与你
    2021-01-14 23:35

    You can get it with this pattern with preg_match_all at the item 0:

    ~
    (?:
        \G (?!\A) # contiguous to previous match, but not at the start of the string
      |
        { (?=[^}]* }) # start with { and check if a closing bracket follows 
      |
        \[ (?=[^]]* ]) # the same for square bracket
    )
    \K # start the match result here
    [A-G] [^]A-G}]* 
    ~xS
    

    demo

提交回复
热议问题