Question

I'm trying get the offset of a regex capture in .NET just like .IndexOf() would return. Is there anyway to do that?

Was it helpful?

Solution

The result of the Regex.Match will be a Match object. Check the Index property of that

Match m = Regex.Match(input, pattern);
int i = m.Index;

hth

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top