我想从此行中枚举“ 4.9.8”。我该怎么办。我是Regex的新手。
import re
url = 'http://variety.com'
line = "<script type=\'text/javascript\' src=\'https://js-sec.indexww.com/htv/htv-jwplayer.min.js?ver=4.9.8\'></script>"
regex = "?ver=(.+?)\'>"
version = re.findall(regex,line)
print(version)
答案 0 :(得分:0)
转义?
特殊字符:
import re
url = 'http://variety.com'
line = "<script type=\'text/javascript\' src=\'https://js-sec.indexww.com/htv/htv-jwplayer.min.js?ver=4.9.8\'></script>"
regex = "\?ver=([0-9.]+)"
version = re.findall(regex,line)
print(version)
返回:
['4.9.8']
我使用了"\?ver=([0-9.]+)"
正则表达式,但您也可以像这样使用您的正则表达式:
regex = "\?ver=(.+?)\\'>"
(也转义\
)