How do I repeat a capturing group?

江枫思渺然 提交于 2019-12-04 15:22:27

Change your regex to,

(.+?CS[[:xdigit:]]{2})

DEMO

You don't need to put the regex inside another capturing group and make it to repeat one or more times. Just print the group index 1 to get your desired output.

(.+?CS.{2})

You can direclty use this.See demo.Grab the group or capture.

https://regex101.com/r/vD5iH9/68

It doesn't seem like you need a capturing group at all:

(?:(?!CS[0-9A-F]{2}).)+CS[0-9A-F]{2}

will match all strings that end in CS + 2 hex digits.

Test it live on regex101.com.

Explanation:

(?:                # Start a group.
 (?!CS[0-9A-F]{2}) # Make sure we can't match CSff here,
 .                 # if so, match any character.
)+                 # Do this at least once.
CS[0-9A-F]{2}      # Then match CSff.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!