I’m parsing the string with TRegExpr. Expression looks like:
(.*$)
It means it should find the whole string, but after finding it when I use command ExecNext, it finds empty string, but the line is over already because of the $ symbol.
Can someone explain such behavior?
Thats because of the
*quantifier. It will match 0 or more occurrences of the character before. 0 Occurrences means it will match the empty string.The
$an anchor, a zero width assertion. It does not match the end of the string, it matches the position before the end of the string (or before a newline that is the last character in the string).So what happens?
Your regex matches at first the string till the end of the string.
The position of the regex engine is after the last character, but before the end of the string. When you call now
ExecNextit matches the empty string before the end of string.If you want to avoid this, use the
+quantifier, it will need at least one character to match ==>.+$will find only one match.