RegHex
RegHex copied to clipboard
Do partial match by expanding the regexp
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.