[Regex] : Unknown character sequence.

Hi, 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]+"); ...... } 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. Any ideas ? Thanks in advance. -- -Sandeep.

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. John.
participants (2)
-
John Maddock
-
Sandeep Bantia