Regex match outer nested tags

前端 未结 4 927
南笙
南笙 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:14

    The regular expression below should do the trick:

    [^\[]*(\[.*\])[^\]]*
    

    You can try a working demo visiting this link.

    Alternatively, if you don't want to rely on capturing groups, this should be enough:

    (\[.*\])
    

    A working demo of the regular expression above can be tested here.

提交回复
热议问题