Regex non-capturing group is capturing

前端 未结 5 1116
礼貌的吻别
礼貌的吻别 2021-01-24 11:35

I have this regex

(?:\\]*?)>

The point of this regex is to capture every closing ta

5条回答
  •  情歌与酒
    2021-01-24 12:31

    Rewrite your regex as :

    (?:\]*?)(>)
       non capture __^^                                    ^ ^
                                                 capture __|_|
    

    As Tony Lukasavage said, there is an unnecessary non-capture group, and, moreover, there is no need to escape <, so it becomes:

      ]*?(>)
    non capture __^^                                    ^ ^
                                              capture __|_|
    

提交回复
热议问题