match the same unknown character multiple times

后端 未结 4 1953
小蘑菇
小蘑菇 2021-01-01 21:41

I have a regex problem I can\'t seem to solve. I actually don\'t know if regex can do this, but I need to match a range of characters n times at the end of a pattern. eg. bl

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-01 21:54

    In most regex implementations, you can accomplish this by referencing a capture group in your regex. For your example, you can use the following to match the same uppercase character five times:

    blahblah([A-Z])\1{4}
    

    Note that to match the regex n times, you need to use \1{n-1} since one match will come from the capture group.

提交回复
热议问题