# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r".*斗地主"
test_str = ("听好听的歌\n\n"
"我想听蜻蜓fm郭德纲的相声\n"
"我要听蜻蜓fm郭德纲的相声等等等等\n"
"蜻蜓的是的是的\n"
"听周杰伦的歌\n"
"蜻蜓fm于谦的相声\n"
"蜻蜓fm的于谦的相声\n"
"想听skds的草根创业最好的项目\n"
"想听刘德华的歌\n"
"我想听于放的相声的地点的电视\n"
"想听好听的音乐\n"
"想听铁齿铜牙纪晓岚\n"
"我想听中国之声\n"
"要听圣诞节\n\n"
"听蜻蜓fm\n\n"
"我想听相声\n"
"好听的歌\n"
"听广播电台\n"
"周杰伦的菊花台\n"
"听fm\n"
"听六千的相\n"
"听加快时间打开手机端\n"
"听有声书\n"
"听音乐\n"
"听蜻蜓fm收银员\n"
"听歌曲\n")
matches = re.finditer(regex, test_str, re.MULTILINE)
for matchNum, match in enumerate(matches, start=1):
print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group()))
for groupNum in range(0, len(match.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum)))
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
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