Regex match outer nested tags

前端 未结 4 928
南笙
南笙 2021-01-16 03:58

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:27

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

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

    See a demo on regex101.com.

提交回复
热议问题