regex_match doesn't match in an embedded string
Hi there, not sure how I could write that Subject line. Sorry :-) Here's the thing, I have a file with the following: KEY1 = ${short_localhost} KEY2 = bbbf<control2.cfg:OTHER_SECTION:${long_localhost}>aaaf:<he I need to extract the value between the {} when it starts with a $. My expression works ok for KEY1 (the value part, the string to the right of the equal sign), however it doesn't match for the value for KEY2. This is what I have: static const boost::regex expression( "\\$\\{(.*?)\\}" ); boost::cmatch what; if ( boost::regex_match( input, what, expression ) ) { cerr << "GOT IT!" << endl; } else { cerr << "NOPE" << endl; } where input is a std::string with the value described above. Why does it work for KEY1 and not KEY2? Interestingly enough, if I do the following: KEY1 = dd${short_localhost} it doesn't match either. This same expression in Perl works fine though. thanks, -Anibal
On 1/16/02 9:17 PM, "soleani" <soleani@yahoo.com> wrote:
Here's the thing, I have a file with the following:
KEY1 = ${short_localhost} KEY2 = bbbf<control2.cfg:OTHER_SECTION:${long_localhost}>aaaf:<he
I need to extract the value between the {} when it starts with a $. My expression works ok for KEY1 (the value part, the string to the right of the equal sign), however it doesn't match for the value for KEY2.
Right. That's because regex_match return true only if the regular expression matches your entire string. If you want to search for a regular expression in a string, you want regex_search. -- Darin
participants (2)
-
Darin Adler
-
soleani