0

I would like to match an even number of digits from a range. Here is a regex which match a number of digits from range:

boost::regex expr("[0-9]{2,20}");

How to modify that regex to match an even number of digits from a range ?

Irbis
  • 1,432
  • 1
  • 13
  • 39

1 Answers1

2

Your pattern [0-9]{2,20} repeats a digit 0-9 from 2 - 20 times.

You could use an anchor to assert the start ^ and the end $ of the string and repeat matching 2 digits between 1-10 times:

^(?:[0-9]{2}){1,10}$

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70