Closed GaidaiIgor closed 4 years ago
I'm afraid I didn't really consider regular expressions that match the empty string. I added you example as a unit test and changed some things in ftlRegex. It now matches the empty string 4 times in "foo", once before the first character, and then after every character. I believe this is correct result.
Thanks for reporting this :)
(I'm not so sure about the overlapping of matches. I think normally matches should not overlap and you have to use tricks like the positive lookahead to get overlapping matches. I'm afraid this will break pretty badly with ftlRegex though ...)
The following program tries to find zero-length match:
The call to r % Match(line) sends the program to an infinite loop because
begin
value inNumMatchesRaw
does not change.Proposed solution: advance
begin
by at least 1:begin = begin + max(m%end - 1, 1)
This fixes infinite loop, but the empty match after the last character of the string would still not be detected.Not sure if overlapping matches are supposed to be supported, but if they are then you could always advance
begin
by 1.