You're lucky because C # is one of the few languages (if not the only one) that supports subexpressions, captures
https://msdn.microsoft.com/en-us/library/system.text.regularexpressions.capture(v=vs.110)
API.NET can be seen as follows
Matches Groups (most regex engines stop here) Captures (unique for .NET)
It’s not clear from your question that you want to match exactly, but this should get you started. Ask again if you are stuck.
string input = "-group1 -group2 "; string pattern = @"(-\S*\W){2}"; foreach (Match match in Regex.Matches(input, pattern)) { Console.WriteLine("Match: {0}", match.Value); for (int groupCtr = 0; groupCtr < match.Groups.Count; groupCtr++) { Group group = match.Groups[groupCtr]; Console.WriteLine(" Group {0}: {1}", groupCtr, group.Value); for (int captureCtr = 0; captureCtr < group.Captures.Count; captureCtr++) Console.WriteLine(" Capture {0}: {1}", captureCtr, group.Captures[captureCtr].Value); } }
It outputs
Match: -group1 -group2 Group 0: -group1 -group2 Capture 0: -group1 -group2 Group 1: -group2 Capture 0: -group1 Capture 1: -group2
As you can see (group 1, capture 0) and (group 1, capture 1) offer separate entries for the group (and not the last, as in most languages)
In this address, I think of what you are describing as "being able to reverse highlight each of the values separately"
(You use the term "backreference", but I don’t think you are aiming to replace the template correctly?)
buckley Jun 15 2018-12-12T00: 00Z
source share