Do partial match by expanding the regexp #4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thanks for coding up this puzzle---I found it really fun.
Here is an implementation of partial matching for each line. It works by using an underscore character, _, to represent a blank square, and then rewriting each regexp to another that accepts underscore characters. The rewriting would be easy if we could work from the recursive definition of a regexp. Here it is a little more complicated since we must parse just enough of the RE syntax to do the rewriting.
One shortcoming of this approach is the back references. There is no way to tell the regexp engine to admit underscores to match characters in a back reference. For example,
(.)\1
should find both_e
ande_
as partial matches. This approach will find neither. (But it will find both__
andee
as partial matches.) The only way to around it seems to write our own regexp engine to match back refs differently. On the other hand, the back references appear to be the only place where valid partial matches are missed.Feel free to close this PR; I wanted to share and it seemed easier than sending an email with a patch.