-1

For example, I have this string:

222

What pattern I should use to get a count of "22" matches exactly 2 times?

222 -> (22)2 and 2(22)

So, for 2222 I would have 3 matches:

2222 -> (22)22 and 2(22)2 and 22(22)
Brm
  • 59
  • 5

2 Answers2

0

You can use Positive Lookahead:

2(?=2)

Example: https://regex101.com/r/gGLv4k/1

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125
-1

Try 2{2}. The number inside the braces is the number of repetitions of the token prior to the opening brace.

Arseny
  • 933
  • 8
  • 16