2

I am using boost::regex to match (better to say boost::regex_search) a text vs a regular expression.

This one doesn't match and my regex is really huge.

Do you know if in the library is there any function telling me which part of the regex failed to match?

I am using LINUX/gcc

     std::string text; // whatever
     boost::regex rgx( "(\\w+) (\\d+) (\\s+)" );
     boost::smatch m;
     if( !boost::regex_search( text, m, rgx ) ){
         // how to know where (\\w+) or (\\d+) or (\\s+) failed?
     }
user229044
  • 232,980
  • 40
  • 330
  • 338
Abruzzo Forte e Gentile
  • 14,423
  • 28
  • 99
  • 173
  • It's designed for Java and not boost, but I still think that http://www.fileformat.info/tool/regex.htm will meet your needs. – Ben Hocking Jul 12 '11 at 20:27

2 Answers2

1

There is no tool for that in the library to my knowledge, but I was using Boost version 1.28.0.

Did you try to execute (\w+), (\d+) and (\s+) independantly of each other? At least one of them should fail matching.

Shlublu
  • 10,917
  • 4
  • 51
  • 70
  • Looking at the docs it seems you are right. Do you know whether is thee any way to say AT wHICH POINT of the string the matching process went wrong? – Abruzzo Forte e Gentile Jul 12 '11 at 22:21
  • Yes, you can determine this by splitting your regex, as I explained above: trying to match each part independantly will show which one fails. – Shlublu Jul 13 '11 at 13:22
  • 1
    Coming back and reviewing this post I can confirm that a good way to check where is the error is to write the regex in multiple lines commenting one by one and do trials. It looks tedious but practically speaking is the way suggested by Shlublu and it work; I created a small application JUST for this task in my test environment. – Abruzzo Forte e Gentile Aug 21 '11 at 12:49
0

Grab kiki asap. It's an invaluable tool for testing and playing with regex.
If you are using a debian based distro, it should be in the base repositories.

Josh
  • 6,155
  • 2
  • 22
  • 26