展开 Python 正则表达式以列出所有可能的字符串

Expand Python regex to list of all possible strings

我是 Python 的新手,也不是全职编码员。我正在尝试查看 python 中是否有任何内置的正则表达式函数可以提供来自 python 正则表达式的完整(扩展)字符串列表。

示例:对于输入:

Good (Morning|afternoon|evening) my (friends|family|brothers|sisters). hope you like (apple|orange|grape) juice

输出应该是:

Good Morning my friends. hope you like apple juice
Good Morning my friends. hope you like orange juice
Good Morning my friends. hope you like grape juice
Good Morning my family. hope you like apple juice
Good Morning my family. hope you like orange juice
Good Morning my family. hope you like grape juice
Good Morning my brothers. hope you like apple juice
Good Morning my brothers. hope you like orange juice
Good Morning my brothers. hope you like grape juice
Good Morning my sisters. hope you like apple juice
Good Morning my sisters. hope you like orange juice
Good Morning my sisters. hope you like grape juice
Good afternoon my friends. hope you like apple juice
Good afternoon my friends. hope you like orange juice
Good afternoon my friends. hope you like grape juice
Good afternoon my family. hope you like apple juice
Good afternoon my family. hope you like orange juice
Good afternoon my family. hope you like grape juice
Good afternoon my brothers. hope you like apple juice
Good afternoon my brothers. hope you like orange juice
Good afternoon my brothers. hope you like grape juice
Good afternoon my sisters. hope you like apple juice
Good afternoon my sisters. hope you like orange juice
Good afternoon my sisters. hope you like grape juice
Good evening my friends. hope you like apple juice
Good evening my friends. hope you like orange juice
Good evening my friends. hope you like grape juice
Good evening my family. hope you like apple juice
Good evening my family. hope you like orange juice
Good evening my family. hope you like grape juice
Good evening my brothers. hope you like apple juice
Good evening my brothers. hope you like orange juice
Good evening my brothers. hope you like grape juice
Good evening my sisters. hope you like apple juice
Good evening my sisters. hope you like orange juice
Good evening my sisters. hope you like grape juice

填充顺序无关紧要。只要我在列表中有输出,就可以了。

您可以使用 Exrex。使用 pip install exrex.

安装

然后在终端执行:

exrex 'Good (Morning|afternoon|evening) my (friends|family|brothers|sisters)\. hope you like (apple|orange|grape) juice\.'

确保不要忘记点 . 之前的反斜杠 \,因为点是正则表达式中的特殊字符。这将 return:

Good Morning my friends. hope you like apple juice.
Good Morning my friends. hope you like orange juice.
Good Morning my friends. hope you like grape juice.
Good Morning my family. hope you like apple juice.
Good Morning my family. hope you like orange juice.
Good Morning my family. hope you like grape juice.
Good Morning my brothers. hope you like apple juice.
Good Morning my brothers. hope you like orange juice.
Good Morning my brothers. hope you like grape juice.
Good Morning my sisters. hope you like apple juice.
Good Morning my sisters. hope you like orange juice.
Good Morning my sisters. hope you like grape juice.
Good afternoon my friends. hope you like apple juice.
Good afternoon my friends. hope you like orange juice.
Good afternoon my friends. hope you like grape juice.
Good afternoon my family. hope you like apple juice.
Good afternoon my family. hope you like orange juice.
Good afternoon my family. hope you like grape juice.
Good afternoon my brothers. hope you like apple juice.
Good afternoon my brothers. hope you like orange juice.
Good afternoon my brothers. hope you like grape juice.
Good afternoon my sisters. hope you like apple juice.
Good afternoon my sisters. hope you like orange juice.
Good afternoon my sisters. hope you like grape juice.
Good evening my friends. hope you like apple juice.
Good evening my friends. hope you like orange juice.
Good evening my friends. hope you like grape juice.
Good evening my family. hope you like apple juice.
Good evening my family. hope you like orange juice.
Good evening my family. hope you like grape juice.
Good evening my brothers. hope you like apple juice.
Good evening my brothers. hope you like orange juice.
Good evening my brothers. hope you like grape juice.
Good evening my sisters. hope you like apple juice.
Good evening my sisters. hope you like orange juice.
Good evening my sisters. hope you like grape juice.