I'm parsing a long string and want to use a regular expression for part of the parsing.
For simplicity, let's say my regex is <[a-z]*>
and I'd like to run it when I get to the first <
.
public int FindEnd(string longStr, int index) {
// longStr[index] == '<'
var match = regex.Match(longStr, index);
if (!match.Success || match.Index != index) {
throw new Exception("Mismatch");
} else {
return index + match.Length;
}
}
I'd like to constrain the regex somehow so that it doesn't go over the entire string, but only looks for strings at the given starting point - is this possible? I tried ^<[a-z]*>
but that didn't work - it wouldn't accept anything (except if index
points to the start of the string).
Note: I'm not trying to parse HTML with a regex.