C# equivalent of java Matcher.hitEnd()
To know if the end has been reached -
I submit that it is as easy as adding (\z)?
at the end of your regex,
or anyplace in your regex where you think could match to the end.
This is a passive check you can do, and it will not interfere with any of
the other constructs in any way.
Here is a C# sample usage:
var str =
"Foo $var1 <br/>Yes\n" +
"......... <br/>\n" +
"......... <br/><br/>\n" +
"Foo $var2 <br/>Yes\n" +
"..........<br/>\n" +
"Yes..........<br/>\n" +
"..........<br/>\n" +
"YesYes";
var rx = new Regex(@"Yes(\z)?");
Match M = rx.Match(str);
while (M.Success)
{
bool bAtEnd = M.Groups[1].Success;
Console.WriteLine("Match = {0} , At end {1}", M.ToString(), bAtEnd);
M = M.NextMatch();
}
Output:
Match = Yes , At end False
Match = Yes , At end False
Match = Yes , At end False
Match = Yes , At end False
Match = Yes , At end True