-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
  • 47
  • 4

2 Answers2

0

You can use Positive Lookahead:

2(?=2)

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

Kirill Polishchuk
  • 52,773
  • 10
  • 120
  • 121
-1

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

Arseny
  • 694
  • 5
  • 15