在python中扩展正则表达式

时间:2019-03-20 17:58:50

标签: python python-3.x

我是python的新手,也不是专职程序员。我试图查看python中是否有任何内置的regex函数,这些函数将提供python字符串的完整列表。例如,如果我的输入=良好(上午),则我的(家人或兄弟姐妹)。希望您喜欢(苹果|橙|葡萄)果汁。输出必须是:

  • 早上好,我的朋友们。希望你喜欢苹果汁 早上好我的朋友们。希望你喜欢橙汁 早上好我的朋友们。希望你喜欢葡萄汁 早上好,我的家人。希望你喜欢苹果汁 早上好,我的家人。希望你喜欢橙汁 早上好,我的家人。希望你喜欢葡萄汁 早上好,我的兄弟们。希望你喜欢苹果汁 早上好,我的兄弟们。希望你喜欢橙汁 早上好,我的兄弟们。希望你喜欢葡萄汁 早上好,我的姐妹们。希望你喜欢苹果汁 早上好,我的姐妹们。希望你喜欢橙汁 早上好,我的姐妹们。希望你喜欢葡萄汁 朋友们,下午好。希望你喜欢苹果汁 朋友们,下午好。希望你喜欢橙汁 朋友们,下午好。希望你喜欢葡萄汁 家人下午好。希望你喜欢苹果汁 家人下午好。希望你喜欢橙汁 家人下午好。希望你喜欢葡萄汁 兄弟们,下午好。希望你喜欢苹果汁 兄弟们,下午好。希望你喜欢橙汁 兄弟们,下午好。希望你喜欢葡萄汁 姐妹们下午好。希望你喜欢苹果汁 姐妹们下午好。希望你喜欢橙汁 姐妹们下午好。希望你喜欢葡萄汁 晚上好我的朋友们。希望你喜欢苹果汁 晚上好我的朋友们。希望你喜欢橙汁 晚上好我的朋友们。希望你喜欢葡萄汁 晚上好,我的家人。希望你喜欢苹果汁 晚上好,我的家人。希望你喜欢橙汁 晚上好,我的家人。希望你喜欢葡萄汁 晚上好,我的兄弟们。希望你喜欢苹果汁 晚上好,我的兄弟们。希望你喜欢橙汁 晚上好,我的兄弟们。希望你喜欢葡萄汁 晚上好,我的姐妹们。希望你喜欢苹果汁 晚上好,我的姐妹们。希望你喜欢橙汁 晚上好,我的姐妹们。希望你喜欢葡萄汁

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

1 个答案:

答案 0 :(得分:0)

您可以使用Exrex。使用pip install exrex安装。

然后在终端中执行:

exrex '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.
相关问题