Boost REGEX regex_match grep option

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


Can any one help me to find whats wrong with my code?
Thanks in advance.

Nothing major wrong with the code, the regex simply doesn't match the string

The regex expects a string that consists of zero or more letters a, followed by exactly \n123, and the string "aaa" doesn't have those characters.
Last edited on
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.
> I am passing following parameters
> bool b = MatchWithGrep("(a)*\\n123", "aaa");

"newline separated" :
1
2
// bool b = MatchWithGrep("(a)*\\n123", "aaa");
bool b = MatchWithGrep( "a*\n123", "aaa" ) ;
JLBorges,

As i had mentioned above

(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).

Also i had tried "a*\n123", and i can see in watch window it takes value "a*n123" and also it does not work.
Topic archived. No new replies allowed.