I want to use regex to parse it into groups
string input = @"(1,2)(3,4)";
Regex.Matches(input, @"\((\d,\d)\)");
The results I get is not only 1,2 and 3,4 but also spaces. Can you guys help me ?
EDIT:
I want to get 2 groups 1,2 and 3,4.
I want to use regex to parse it into groups
string input = @"(1,2)(3,4)";
Regex.Matches(input, @"\((\d,\d)\)");
The results I get is not only 1,2 and 3,4 but also spaces. Can you guys help me ?
EDIT:
I want to get 2 groups 1,2 and 3,4.
string input = @"(1,2)(3,4)";
MatchCollection inputMatch= Regex.Matches(collegeRecord.ToString(), @"(?<=\().*?(?=\))");
For current string you will get two outputs:
inputMatch[0].Groups[0].Value;
inputMatch[0].Groups[1].Value;
Or
You can also try foreach loop
foreach (Match match in inputMatch)
{
}
I have not tested this code,
My Working Example:
MatchCollection facilities = Regex.Matches(collegeRecord.ToString(), @"<td width=""38"">(.*?)image_tooltip");
foreach (Match facility in facilities)
{
collegeDetailDH.InsertFacilityDetails(collegeDetailDH._CollegeID, facility.ToString().Replace("<td width=\"38\">", string.Empty).Replace("<span class=\"icon_", string.Empty).Replace("image_tooltip", string.Empty));
}
Try looking at this pattern:
(\((?:\d,\d)\))+
+ allows that the group is repeating and can occur one or more time.
You need to use lookarounds.
string input = @"(1,2)(3,4)";
foreach (Match match in Regex.Matches(input, @"(?<=\().*?(?=\))"))
Console.WriteLine(match.Value);
If your string may have other content then digits in brackets, and you need only those with digits inside, you can use more specific regex as follows.
string input = @"(1,2)(3,4)";
foreach (Match match in Regex.Matches(input, @"(?<=\()\d,\d(?=\))"))
Console.WriteLine(match.Value);