The regex foo/(\w*)/bar matches the string foo/123/bar.
This is probably something basic that I’ve missed about regexes, but often I only want to retrieve the substring between the slashes. Is there a simple .NET API I can use without having to access the groups collection? Or an alternative way of writing the regex?
Thanks!
It is possible using lookaround:
applied to foo/123/bar. matches “123”. Groups are a better method and bear in mind that lookaround (in particular look behind) is not supported in all regex tools, but it is in .net.
note: \w is shorthand for a character class, you don’t need to put it inside []