R
R
riazantsev962016-06-12 20:36:25
C++ / C#
riazantsev96, 2016-06-12 20:36:25

How to build such a regular expression?

You want to write a function that returns a regular expression to check if a string is an unsigned integer (with arbitrary indentation).

std::regex getRegex(unsigned length, unsigned minLength)
{
    std::assert(minLength <= length);
    // ...
}

Valid examples:
12345
 2345
  345
   45
    5

It is possible directly through OR, but then the number of ORs will be equal to length - minLength, which is not good if there is a large difference between them (the regular expression will be very long).

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
ADRian, 2016-06-12
@riazantsev96

(?= *\d+).{5}
https://www.debuggex.com/r/zavW3W9gxmoFKzJQ

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question