Getting Name Subgroups

I am working with the new version of boost 1.42, and I want to use a regex with named subgroups. Below is an example.

std::string line("match this here FIELD=VALUE in the middle");
boost::regex rgx("FIELD=(?<VAL>\\w+)", boost::regex::perl );
boost::smatch thisMatch;
boost::regex_search( line, thisMatch, rgx );

Do you know how to get match content? The traditional way is

std::string result( mtch[1].first, mtch[1].second );

but I do not want to use this method.

I want to use the name of the subgroups, as usual, in Perl and in regular expression in general. I tried this, but it did not work.

std::string result( mtch["VAL"].first, mtch["VAL"].second );

Do you know how to get the value using the name of a subgroup?

Thanks AFG

+3
source share
2 answers

AFAIK, . . , , Perl Boost.Regex. boost::match_results<IteratorType> .

+1

- , .

std::cout << mtch["VAL"] << std::endl;

, .

, , 1.42 , .

+1

Source: https://habr.com/ru/post/1736638/


All Articles