Suppose I check whether a string match a regex with wildcard. How can I programatically get extract which substring replaces the wildcard?
Simple example: the regex is "[foo|bar].*\.txt" and say, a matching string that is found is “foo123.txt”. In this case the answer I want is “123”, since it is the substring that replaces the wildcard. If a matching string is bar0123456789.txt, then the answer is 0123456789.
I use c#, but I wouldn’t mind answers in other languages that I can also implement in c#
Don’t use square brackets, if you want a group. Square brackets create a character class.
What you want is a non capturing group for that:
To get the result from the
.*(.is a special character that matches any character, but Newline characters (by default) and*is a quantifier that repeats the previous character 0 or more times), you need to put it into a capturing group.