I have a string which contains some functions (I know their names) and their parameters like this: translate(700 210) rotate(-30)
I would like to parse each one of them in a string array starting with the function name followed by the parameters.
I don't know much abour regex and so far I got this:
MatchCollection matches = Regex.Matches(attribute.InnerText, @"((translate|rotate|scale|matrix)\s*\(\s*(-?\d+\s*\,*\s*)+\))*");
for (int i = 0; i < matches.Count; i++)
{
Console.WriteLine(matches[i].Value);
}
That this returns is:
translate(700 210)
[blank space]
rotate(-30)
[blank space]
This works for me because I can run another regular expression one each row from the resulting collection and get the contents. What I don't understand is why there are blank rows returned between the methods.
Also, is running a regex twice - once to separate the methods and once to actually parse them a good approach?
Thanks!
*to+, or when I eliminate the outer parens and*entirely, I don't get the empty matches. The outermost parens are unnecessary anyway -- in fact, worse than unnecessary. It matches the regex you give it as many times as possible. Your regex, "zero or more of this stuff", happens to match nothing.