I would like to find all possible matches of regex, how is it possible?
regex rx("(2|25)");
string s = "2225";
for (sregex_iterator it(s.begin(), s.end(), rx), end; it != end; ++it) {
cout << it->position() << ": " << it->str() << endl;
}
Gives output:
0: 2
1: 2
2: 25
But can't find third 2: 2
exactly. I prefer to use regex because of O(n)
complexity for searching several tokens at same time.
UPDATE:
Maybe split token list to non-prefixable lists and create several regexes? For example: (2|4|25|45|251|455|267)
=> (2|4)
, (25|45|267)
, (251|455)
This will grow complexity to something like O(n log(m))
UPDATE 2:
Please, provide short STL-based algorithm of splitting token vector to non-prefixable vectors to answer this question.