hello everybody i have a trouble with regex_match function. when i try to match a string with a pattern like "(abc)*", and if the string beeng matched contains several subexpressions 'abc', regex_match returns only one match so that i can't iterate through all of them. so, it counts subexp's in the pattern, not in the string. why it happens (i use default flags for regex_match, which must perform what i expect)? and what is the solution to the problem (the one i found so far is to parse in 2 phases - once with regex_match to be sure that the whole string matched, and then to use regex_split. but i'd like to parse the string only once and obtain all the subexp's)? thanks in advance aram
hello everybody
i have a trouble with regex_match function. when i try to match a string with a pattern like "(abc)*", and if the string beeng matched contains several subexpressions 'abc', regex_match returns only one match so that i can't iterate through all of
Use regex_grep instead.and create a Predicate for handling each match found.
regex_match, which must perform what i expect)? and what is the solution to the problem (the one i found so far is to parse in 2 phases - once with regex_match to be sure that the whole string matched, and then to use regex_split. but i'd like to parse the string only once and obtain all the subexp's)?
i have a trouble with regex_match function. when i try to match a string with a pattern like "(abc)*", and if the string beeng matched contains several subexpressions 'abc', regex_match returns only one match so that i can't iterate through all of them. so, it counts subexp's in the pattern, not in the string. why it happens (i use default flags for regex_match, which must perform what i expect)? and what is the solution to the problem (the one i found so far is to parse in 2 phases - once with regex_match to be sure that the whole string matched, and then to use regex_split. but i'd like to parse the string only once and obtain all the subexp's)?
What you are seeing is the way that all regex libs work - when a marked sub-expression is repeated you get the last repeat. You can BTW use regex_split for this with a shortened expression that matches what you want only once (it will then search through the string and spit out all occurrences). John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
thanks to all for answers
On Sat, 24 Aug 2002 11:27:47 +0100, "John Maddock"
What you are seeing is the way that all regex libs work - when a marked sub-expression is repeated you get the last repeat.
just interesting - why it had been implemented that way instead of getting all actual matches? had it been intended specially for some reason? regards, aram
just interesting - why it had been implemented that way instead of getting all actual matches? had it been intended specially for some reason?
Well as I said all the regex libs out there (including perl) do it that way, there is also an efficiency reason: how many marked repeats are you prepared to store, and how do you apply the "leftmost longest" rule if there isn't one unambiguous answer to "what matched sub-expression N?". John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
participants (3)
-
Edward Diener
-
John Maddock
-
yg-boost-users@m.gmane.org