Discussion:
[Regex] : Unknown character sequence.
Sandeep Bantia
2006-02-08 03:22:33 UTC
Permalink
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.
Sohail Somani
2006-02-08 03:42:20 UTC
Permalink
________________________________

From: boost-users-***@lists.boost.org
[mailto:boost-users-***@lists.boost.org] On Behalf Of Sandeep Bantia
Sent: Tuesday, February 07, 2006 7:23 PM
To: boost-***@lists.boost.org
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.
paul\.floyd
2006-02-08 09:11:37 UTC
Permalink
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)
John Maddock
2006-02-08 10:28:56 UTC
Permalink
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.

Continue reading on narkive:
Loading...