Jimbly / regex-crossword

Implementation of a RegExp crossword.
287 stars 27 forks source link

Greedy matching breaks a clue #21

Closed TheOriginalSoni closed 3 years ago

TheOriginalSoni commented 3 years ago

For (...?)\1* the pattern matching is greedy, which will always accept strings of the form ABCABCABCABC, but fail to match strings like ABABABABABAB

This is because for ? it tries to match maximum number of letters possible (ABA). And then the rest of regex doesn't work anymore. Instead. ? should probably iterate through both options and return True if either is True.

Jimbly commented 3 years ago

Thanks, good catch! I guess in JavaScript we do need to prepend/append ^ and $ to do a full match...