0

Based off a regex string I would like to get a list of all the possible strings that would match the regex.

Example: Given a regex string like... ^(en/|)resources/case(-| )studies/

I want to get a list of all the possible strings that would match the regex expression. Like...

^en/resources/case-studies/

or ^/resources/case-studies/

or ^en/resources/case studies/

or ^/resources/case studies/

Thank you

scouty
  • 145
  • 1
  • 10
  • 1
    This is not possible in general. For example, a regex of the form `.` would have to spit out all possible Unicode characters -- and that's *one* character. Algorithms can be written that work a little more high level, but writing those is definitely outside the scope of one answer. There is, in any case, no built-in functionality in the framework for this. (Also, `^` does not actually match any character; it anchors the regex to the beginning of the line.) – Jeroen Mostert May 22 '19 at 14:41

1 Answers1

0

Note that in regex ^ denotes the beginning of the line. You must escape it

Try

\^(en)?/resources/case(-|\s)studies/

explanation:

\^ is ^ escaped.

(en)? is optionally en, where ? means zero or one times.

/resources/case the text as is.

(-|\s) minus sign or white space.

studies/ the text as is.

See: https://dotnetfiddle.net/PO4wKV

Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188