Given a Regex like this:
(aaa)(bbb)*(ccc|ddd)
Is there any way to list all the possible values that will come after a token (for example aaa
) and will match the regex?
Of course here the answer is ["bbb","ccc","ddd"]
but look at it as a general question.
Notes:
- It's not a question of how to write a Regex.
- Regex is used only as an instruction to generate the list.
- Yes! you guessed right: one of the use cases is code-completion.
- If it cannot be done (or too complicated) for the full set of Regex let's consider a simpler subset which only includes "parenthesis ()", repartitions of "zero-or-more *", "one-or-more +" and "or |"