2013/12/27 Asmita Gaikwad <asmita.gaikwad@edisphere.com>

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");

I think your problem is "\\n". Shouldn't it be "\n"? (Not tested, reasoning from the doc you qouted below)
HTH, Kris

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 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