tom-lord/regexp-examples

Enhancements to absent operator examples

tom-lord opened this issue · 0 comments

The "best" way to replicate generating examples for absent operator groups is with a negative lookbehind, e.g:

(?~abc) --> (?:.(?<!abc))*

But since look-behinds are irregular, this library cannot support that! A possible workaround would be to replace the group with a repetition of the first letter negated, e.g:

(?~abc) --> (?:[^a]*)

However (!!) this generalisation is not always possible:

(?~\wa|\Wb) --> ???

Therefore, the only 100% reliable option - which is what this gem currently does - is just to match "nothing"!

/(?~abc)/.examples #=> [""]

However, as shown above, this library could, at least, be enhanced to deal with specific scenarios in better ways. But such a strategy needs to be optimised for generalisation and reliability.