Boost regex does not match

Pascal Neubert

I made a python regular expression and now I'm supposed to code the program in C++.

I was told to use boost's regex by the respective person.

It is supposed to match a group of at least one to 80 lower alphanumeric characters including underscore followed by a backslash then another group of at least one to 80 lower alphanumeric characters again including an underscore and last but not least a question mark. The total string must be at least 1 character long and is not allowed to exceed 256.

Here is my python regex:

^((?P<grp1>[a-z0-9_]{1,80})/(?P<grp2>[a-z0-9_]{1,80})([?])){1,256}$

My current boost regex is:

^(([a-z0-9_]{1,80})\/([a-z0-9_]{1,80})([?])){1,256}$

Cut down basically my code would look like this:

boost::cmatch match;
bool isMatch;
boost::regex myRegex = "^(([a-z0-9_]{1,80})\/([a-z0-9_]{1,80})([?])){1,256}$";
isMatch = boost::regex_match(str.c_str(), match, myRegex);

Edit: whoops totally forgot the question xDD. My problem is quite simple: The regex doesn't match though it's supposed to.

Example matches would be:

  • some/more?
  • object/value?
  • devel42/version_number?
Pascal Neubert

The actual error was a new line sent to the server by the client on entering the respective string that would've been later compared.

Funny how the errors root is rarely where you expect it to be.

Anyways, thank you all for your answers. They gave me the ability to clean up my regular expressions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related