This can be done using the callback function.
I am a Java program, so I will show you how to do it in Java (for C #, see here ).
final Pattern aPattern = Pattern.compile("([A-Z]).*\\1");
final Matcher aMatcher1 = aPattern.matcher("ABCDA");
System.out.println(aMatcher1.find());
final Matcher aMatcher2 = aPattern.matcher("ABCDA");
System.out.println(aMatcher2.find());
There is a regular express ([A-Z]).*\\1translating to anything between 'A' to 'Z' as group 1 ('([A-Z])') anything else (.*) and group 1.
Use $1for C #.
Hope this helps.
source
share