0

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 |"
el_shayan
  • 2,735
  • 4
  • 28
  • 42
  • Seems possible, what language? – ergonaut Sep 21 '15 at 14:29
  • Doesn't matter. I'm looking for the algorithm. Pseudocode is fine. – el_shayan Sep 21 '15 at 14:36
  • There are infinite possibilities on a regex expression. If your regex format is flat as above, then I suppose you can build a parser to tokenize it and generate all possibilities. If it has more depth (eg. (((aaa|bbb)|c))? that would be trickier to do. – ergonaut Sep 21 '15 at 14:47

0 Answers0