Regex match outer nested tags

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

    I dont get your decision to use the \s\S and it just seems more confusing than it really should be. However to fix the issue you are having simply remove the ?

    ...([\s\S]*?)\[EC]...
    

    to

    ...([\s\S]*)\[EC]...
    

    resulting into

    \[IC=\"([\s\S]*?)\"]([\s\S]*)\[EC]\n{0,1}
    

    however i would simply use \w and .* because they are easier

    \[IC="(\w*)"\](.*)\[EC\]
    

    EDIT:

    Working off of the assumption that you actually need to get the string value from [IC=".."] and string inbetween. otherwise if you just need whole data then no need for the groupings

    \[IC="\w*"\].*\[EC\]
    

提交回复
热议问题