我想通过正则表达式打印列表元素,这是我的代码:

myresult_tv = [ 'Extinct A Horizon Guide to Dinosaurs WEB h264-WEBTUBE', 'High Noon 2019 04 05 720p HDTV DD5 1 MPEG2-NTb', 'Wyatt Cenacs Problem Areas S02E01 1080p WEBRip x264-eSc', 'Bondi Vet S05E15 720p WEB x264-GIMINI', 'If Loving You Is Wrong S04E03 Randals Stage HDTV x264-CRiMSON', 'Wyatt Cenacs Problem Areas S02E01 WEBRip x264-eSc', 'Bondi Vet S05E15 1080p WEB x264-GIMINI']


li = []

for a in myresult_tv:
    w = re.match(".*\d ", a)
    c =w.group()
    li.append(c)

print(li)


结果是:

    Traceback (most recent call last):
  File "azazzazazaaz.py", line 31, in <module>
    c =w.group()
AttributeError: 'NoneType' object has no attribute 'group'

***Repl Closed***

最佳答案

您无需检查正则表达式是否与列表中的元素匹配。您应该这样做:

match = re.search(pattern, string)
if match:
    process(match)

关于python - 如何在Python中的正则表达式中获取列表的所有元素,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55551230/

10-12 00:27