devongovett / regexgen

Generate regular expressions that match a set of strings

Home Page:https://runkit.com/npm/regexgen

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[question] revert the process

Kikobeats opened this issue · comments

Do you think that could be more or less easy to exactly the invert operation?

For example, return an array of all variations:

r[ae]d → ['red', 'rad']

Definitely possible. I did something similar for fontkit. Here's the algorithm you could implement:

  1. Parse the regex into an AST.
  2. Convert the regex into a DFA. Something like this.
  3. Treat the DFA as a graph, and do a depth first search. Upon finding an accepting state, add it to the result set.