Regex match outer nested tags

前端 未结 4 2027
走了就别回头了
走了就别回头了 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:10

    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.

提交回复
热议问题