我在这里有这个字符串:
"['\r\n File: FLO_JIUWASOKLDM_05_HetR_IUSJA_&_Cracks.mp4', <br/>, '\r\n Size: 48.14 MB ']"
我有这个正则表达式\w+\.\w+
我想让正则表达式得到文件名FLO_JIUWASOKLDM_05_HetR_IUSJA_&_Cracks.mp4
但它在与号处中断,这将返回_Cracks.mp4
,我需要做什么来修复它?我是Regex的新手。
发布于 2019-06-14 01:31:39
这里有许多选项可供选择,例如,其中一个选项:
([^\s]+\.[a-z][a-z0-9]+)
测试
# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"([^\s]+\.[a-z][a-z0-9]+)"
test_str = "\"['\\r\\n File: FLO_JIUWASOKLDM_05_HetR_IUSJA_&_Cracks.mp4', <br/>, '\\r\\n Size: 48.14 MB ']\"
"
matches = re.finditer(regex, test_str, re.MULTILINE | re.IGNORECASE)
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.
https://stackoverflow.com/questions/56585758
复制相似问题