regex groups

  • Thread starter Thread starter dwight
  • Start date Start date
D

dwight

How does one figure out match.groups for a regex string? Here is the
expression,
"([12]\d{3}-[A-Z]\d{3})(\d{3})?((-)(\d{4})(\d{2}))?((-)(0\d{2})(\d{2}))?((-)(0\d{2})(\d{2}))?((-)(0\d{2})(\d{2}))?"
and here is an example string 1013-A109400-480001-00701-05601-06501 .


I've tried searching msdn and the net and nothing seems to make sense
to me.

Thanks

Dwight
 
How does one figure out match.groups for a regex string? Here is the
expression,
"([12]\d{3}-[A-Z]\d{3})(\d{3})?((-)(\d{4})(\d{2}))?((-)(0\d{2})(\d{2}))?((-)(0\d{2})(\d{2}))?((-)(0\d{2})(\d{2}))?"
and here is an example string 1013-A109400-480001-00701-05601-06501 .

Give the groups a name by prefixing with "?<name>, e.g. (untested)

Match m = Regex.Match(s, @"(?<s1>\d+)(?<s2>\d+)");
System.Console.WriteLine("s1: " + s1 + ", s2: " + m.Groups["s2"]);

HTH & kind regards
frank
 
Back
Top