Tuesday, May 3, 2011

regex: matching same expression unknown number of times

Hi, With the help of some of the guys here I have some regex to match strings in quotes that aren't in brackets:

"one" - matches
("two") - doesn't match

Is it possible to repeat the match so the input:

"one" ("two") "three"

would return one and three? The only thing I can think of doing is capturing whatever is left over and reprocessing with the same regex, i.e:

process > "one" ("two") "three" - returns one and "("two") "three""
process > ("two") "three"       - returns failed and "three", not sure how but hey
process > "three"

I'm learning regex at the moment so just wondering if this functionality is built in?

NB: this may be a repeat of http://stackoverflow.com/questions/638113/refering-to-already-existing-group-in-regex-c but not clearly enough for me to follow :(.

From stackoverflow
  • You need the Regex.Matches() function which returns all of the substrings that match the regex.

0 comments:

Post a Comment