How to extract a search term using boost::regex in C++ , especially when the term has html entities in it.
Eg
p=test&test&sort=price
Search Term would be 'test&test'
p=test&test&sort=price
Search Term would be 'test&test'
Boost Regex code is as follows
bool regexExtract(const string &strInput,string &strOutput,const string& regex)
{
bool succ = false;
if ( ! strOutput.empty() )
{
boost::regex re(regex, boost::regex::perl);//,boost::regex::perl | boost:regex::icase);
boost::sregex_iterator res(strInput.begin(),strInput.end(),re);
boost::sregex_iterator end;
for (; res != end; ++res)
cout << (*res)[0] << std::endl;
}
return succ;
}
with regex string re = "p=(([^&;#]|(&.*?;))*).*";
it prints below
p=test&test&sort=asc
while same regex in perl works perfectly fine
echo "p=test&asd;test&sort=asc" | perl -ne 'if ( $_ =~ /p=(([^\&;#]|(&.*?;))*).*/){print $1;}'
test&asd;test