Regex match outer nested tags

前端 未结 4 2067
走了就别回头了
走了就别回头了 2021-01-16 03:43

I have this string

blabla [IC=\"test\"]Hello, [IC=\"testing\"] this is a nested tag [EC], cya.[EC] blabla

I\'m trying to match the outer [

4条回答
  •  余生分开走
    2021-01-16 04:07

    You could use a recursive pattern (supported in PCRE):

    \[IC[^][]*\]
    (?:(?:[^][]*|(?R))*)
    \[EC\]
    

    See a demo on regex101.com.

提交回复
热议问题