Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do partial match by expanding the regexp #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dbrower
Copy link

@dbrower dbrower commented Jun 6, 2018

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 and e_ as partial matches. This approach will find neither. (But it will find both __ and ee 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.

Since the expanded regexp matches everything the original one does, we
don't need to match on original regexp. Full and partial matches can be
distinguished by the presence of an underscore character in the test
string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant