0

I have a list of strings that include some regular expressions-like strings that define ALL possible matches to form new strings. Example:

Source

Id[0-1][2-3]_Pos[1-3]
foo01_bar[A-C]

Is there any way in Python I can loop trough all possibilities and create new strings from it? So, the example above shall deliver:

Target

Id02_Pos1
Id02_Pos2
Id02_Pos3
Id03_Pos1
Id03_Pos2
Id03_Pos3
Id12_Pos1
Id12_Pos2
Id12_Pos3
Id13_Pos1
Id13_Pos2
Id13_Pos3
foo01_barA
foo01_barB
foo01_barC

Any hints are welcomed.

Update:

A working example of the answer can be found here: http://pyparsing.wikispaces.com/file/view/invRegex.py

Ñhosko
  • 723
  • 2
  • 8
  • 25
  • 1
    In the marked as duplicate question, the user asks for "ANY string that will match that regex", my question is for getting ALL strings that will match that regex. – Ñhosko Dec 19 '17 at 12:27
  • Are you talking about "regex" here, or "regex-like strings in a very specific, limited notation"? If the former, how to loop through all the possibilities for `".*"`? If the latter, please clarify. – tobias_k Dec 19 '17 at 12:29
  • regex-like strings in a very specific, limited notation. The source will include mostly numbers [0-9]. – Ñhosko Dec 19 '17 at 12:34
  • So, the only "regex" element in your strings will be something like `[x-y]`, is this correct? No multiplicities, optional elements, lookaheads, backreferences, etc.? – tobias_k Dec 19 '17 at 12:39
  • Yes, that's correct. The source is very basic and straight forward. The only possible options are: [0-9], [A-Z] and [a-z]. – Ñhosko Dec 19 '17 at 12:42
  • Pyparsing is no longer hosted on wikispaces.com. Go to https://github.com/pyparsing/pyparsing – PaulMcG Aug 27 '18 at 12:35

0 Answers0