> I'm new to regex. This is basically what I was trying.
> #include <iostream>
> #include <boost/regex.hpp>
> int main()
> std::string input = "sand._12";
> boost::regex reg(".*\._[0-9]+");
In C++, you need to double your escape characters, so that in
order to pass '.*\._[0-9]+' to the RE, you need to pass
'.*\\._[0-9]+' to the compiler.
With the string that you use, the compiler will strip the sole
backslash, and the RE will get '.*._[0-9]+', which isn't what
Accédez au courrier électronique de La Poste : www.laposte.net ;
3615 LAPOSTENET (0,34 /mn) ; tél : 08 92 68 13 50 (0,34/mn)
> I get a warning which says "Unknown escape sequence '\.' . Its the
> same case with any other special character or even '\s' .
> I guess I'm missing something very simple.
Yep: escapes are parsed first by the compiler *before* the regex engine gets
to see the string, the compiler is complaining because \. is not a valid
escape sequence for strings in C++. You want to use "\\." so that a literal
'\' gets passed through to the regex engine to see: it then handles the '\.'
sequence as a regex.