c++ - How to get all possible matches of std::regex -


i find possible matches of regex, how possible?

regex rx("(2|25)"); string s = "2225"; (sregex_iterator it(s.begin(), s.end(), rx), end; != end; ++it) {     cout << it->position() << ": " << it->str() << endl; } 

gives output:

0: 2 1: 2 2: 25 

but can't find third 2: 2 exactly. prefer use regex because of o(n) complexity searching several tokens @ same time.

update:

maybe split token list non-prefixable lists , create several regexes? example: (2|4|25|45|251|455|267) => (2|4), (25|45|267), (251|455) grow complexity o(n log(m))

update 2:

please, provide short stl-based algorithm of splitting token vector non-prefixable vectors answer question.

i dont think it's possible iterator , single regexp. here's how works.

your regexp searches substring either "2" or "25". now, start search sregex_iterator. starts first symbol of string, , tries find match regular expression. if there match, "recorded", , iterator advanced position after match. if there no match, iterator advanced 1 position forward. process continues until end of string reached.

now, each time finds match try find best (i.e., longest) match regular expression. if substring matches both 2 , 25, take 25 since it's longer. i'd need 2 regular expressions.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -