0

I found regular expression which should match IPv4 address:

QRegExp rx_ipv4("^((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])$");
bool match = rx_ipv4.exactMatch("1.2.33333");

It returns true.

But in above regular expression part ending with dot must be repeated three times. What is wrong with this regular expression ?

StackPeter
  • 324
  • 2
  • 10
  • The regexp seems to be fine based on [regexr](https://regexr.com/46qfi). Maybe QRegExp doesn't support some part of it or there's some other issue? – Sami Kuhmonen Jan 21 '19 at 15:14
  • I tried it also with std::regex_match(). Result is the same. Is above regular expression right or is it bug in std ? – StackPeter Jan 21 '19 at 15:16

1 Answers1

0

Above regular expression is not right in C++ code. C++ standard escape sequences does not contain: '\.'

C++ escape sequences

Right IPv4 regular expression in C++ is:

QRegExp rx_ipv4("^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\x2E){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$");

where \x2E is Ascii code for '.'

StackPeter
  • 324
  • 2
  • 10