import re
regex = re.compile(r"^.{0,1}(陪我一起)?听?你?(再|快|先)?能?(给我)?唱?(啊|一?个|吧|出来|一?首)?歌?(给我听|来听听)?(吧|啊|哇|呗|呀)?((好(么|嘛|吗))|好不好|小万|亲爱的|这么难)?.{0,1}$", flags=re.MULTILINE)
test_str = ("你先唱给我听好吗\n"
"快唱啊\n"
"快唱啊你\n\n"
"你唱吧\n"
"你唱一个\n"
"唱一首吧亲爱的\n"
"再唱一首\n"
"你快唱吧\n"
"你能唱出来吗\n"
"唱出来\n"
"唱一个给我听呗好不好\n"
"快唱\n"
"唱\n"
"唱吧\n"
"你唱啊\n"
"唱一个嘛\n"
"唱一个啊\n"
"来听你唱歌\n"
"再给我唱一首呗\n"
"唱歌小万\n"
"你唱首歌给我听呗\n"
"陪我一起唱歌好吗\n"
"听你唱歌这么难\n"
"唱首歌来听听\n\n\n"
"你唱歌好好听啊再给我唱一首呗\n\n"
"我现在就很不开心你唱首歌给我听呗\n\n"
"会不会唱歌,唱首歌来听听")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}")
for group_num, group in enumerate(match.groups(), start=1):
print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html