Hi all,
I have a small problem when trying out a regex that works ok with both
jakarta (java code) and Perl. However, in boost::regex I get an extra space
that's very weird. This is the code:
#include <iostream>
#include <string>
#include
main()
{
static const boost::regex infileRedirection(
"\\[(.+?)\\s*=\\s*(.+?)\\]" );
const string input = "[IN_FILE_REDIRECTION = STARTS_3]";
boost::cmatch what;
if ( boost::regex_search( input, what, infileRedirection,
boost::regbase::perl ) )
{
cerr << "Matched! == input is (" << input << ")" << endl;
string mySection;
mySection.assign( what[1].first, what[1].second );
string newSectionName;
newSectionName.assign( what[2].first, what[2].second );
cerr << "mySection is: --" << mySection << "--" << endl;
cerr << "newSection is: --" << newSectionName << "--" << endl;
}
else
{
cerr << "Didn't match" << endl;
}
return 0;
}
And this is the output:
[anibal@anibal ControlFile]$ ./a.out
Matched! == input is ([IN_FILE_REDIRECTION = STARTS_3])
mySection is: --IN_FILE_REDIRECTION--
newSection is: -- STARTS_3--
Please note the extra space in the newSection. That should be STARTS_3 and
not " STARTS_3". Why is it taking that space if the space itself is not in
the () expression?
Any help greatly appreciated,
-Anibal