[Regex] : Unknown character sequence.

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

[Regex] : Unknown character sequence.

Sandeep Bantia
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.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Regex] : Unknown character sequence.

Sohail Somani
 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Sandeep Bantia
Sent: Tuesday, February 07, 2006 7:23 PM
To: [hidden email]
Subject: [Boost-users] [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]+");
 
 If you're trying to escape the "." you probably also need to escape the "\" by using "\\". It is a C string after all.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Regex] : Unknown character sequence.

paul.floyd
In reply to this post by Sandeep Bantia
> 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]+");

Hi

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
you want.

A+
Paul


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)




_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: [Regex] : Unknown character sequence.

John Maddock
In reply to this post by Sandeep Bantia
> 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.

_______________________________________________
Boost-users mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/boost-users