Algorithm for finding strings that a specific Regex will match

后端 未结 2 1239
慢半拍i
慢半拍i 2021-02-15 23:59

Given a regex pattern, I\'m trying to find a string that matches it. Similar to how Django reverses them, but in C#. Are there any pre-made C# libraries that do this?


相关标签:
2条回答
  • 2021-02-16 00:33

    "Are there any pre-made C# libraries that do this?"

    NO

    (I expect this will be accepted as the answer momentarily)

    0 讨论(0)
  • 2021-02-16 00:47

    see for example Using Regex to generate Strings rather than match them

    also you can take a look at http://en.wikipedia.org/wiki/Deterministic_finite-state_machine especially at "Accept and Generate modes" section.

    as others noted you will need to create a DFA from your regular expression and then generate your strings using this DFA.

    to convert your regular expression to DFA, generate NFA first (see for example http://lambda.uta.edu/cse5317/spring01/notes/node9.html) and then convert NFA to DFA.

    the easiest way i see is to use a parser generator program for that. i do not think django does this.

    hope this helps.

    0 讨论(0)
提交回复
热议问题