Say, I have a string that I need to verify the correct format of; e.g. RR1234566-001 (2 letters, 7 digits, dash, 1 or more digits). I use something like:
Use grouping and Matches instead.
I.e.:
// NOTE: pseudocode.
Regex re = new Regex("(\\d+)-(\\d+)");
Match m = re.Match(stringToMatch))
if (m.Success) {
String part1 = m.Groups[1].Value;
String part2 = m.Groups[2].Value;
return true;
}
else {
return false;
}
You can also name the matches, like this:
Regex re = new Regex("(?\\d+)-(?\\d+)");
and access like this
String part1 = m.Groups["Part1"].Value;
String part2 = m.Groups["Part2"].Value;