Boost logo

Boost Users :

Subject: [Boost-users] Boost [Regex] (grep Falg) Why doesn't this pattern match?
From: Asmita Gaikwad (asmita.gaikwad_at_[hidden])
Date: 2013-12-27 02:56:52


Hi,

Environment: Windows 7 (32 bit), Visual Studio 2010 (Visual C++)

I am trying to use Boost REGEX regex_match algorithm.
I am using its grep flag.
My code is as follows and here (a)* matches string "aaa", but still b comes
out to be false.

1
2
3
4
5
6
7
8
9
10
11

bool MatchWithGrep(string& pattern, string& data)

{

 

        const boost::regex e(pattern.c_str(), boost::regex::grep);

        return regex_match(data.c_str(), e);

 

}

 

I am passing following parameters

bool b = MatchWithGrep("(a)*\\n123", "aaa");

 

 

 

In Boost Help, following is documented.

Link -
http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/
basic_syntax.html

When an expression is compiled with the flag grep set, then the expression
is treated as a newline separated list of POSIX-Basic expressions, a match
is found if any of the expressions in the list match, for example:

boost::regex e("abc\ndef", boost::regex::grep);

will match either of the POSIX-Basic expressions "abc" or "def".

Considering this, in my example i have 2 basic expressions (a)* and 123.
(Since its c++ string \\n <file:///\\n> will be taken as \n internally. I
had debugged the code and i can see value of variable pattern as "(a)*\n123"
in watch window).
Presence of any should give me bool b as true. And my data is "aaa". So it
should give true. But i am getting false.

 

Can anyone help me to find what's wrong with my code?

 

 

Thanks & Regards,

Asmita

 

 

EDISPHERE Software Private Limited

Email: asmita.gaikwad_at_[hidden]| Website: <http://www.edisphere.com/>
http://www.edisphere.com

 

 

 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net