为什么正则表达式[$-\ _ @。&+]也可以在python3.8中匹配符号'/'和'='

时间:2020-05-04 15:47:51

标签: python python-3.x regex

我想知道为什么[$ -_ @。&+]还能在python3.8中匹配符号'/'和'='。
正则表达式[$ -_ @。&+]不应仅与“ $”“-”“ _”“ @”“匹配。 '&''+'?
例如

拥有[$ -_ @。&+]

>>> a = 'https://jq.qq.com/?_wv=1027&k=57a4SWD'
>>> share_url = re.findall(r'http[s]?:/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\), ]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',a)
>>> share_url
['https://jq.qq.com/?_wv=1027&k=57a4SWD']
>>>

无[$ -_ @。&+]

>>> a = 'https://jq.qq.com/?_wv=1027&k=57a4SWD'
>>> share_url = re.findall(r'http[s]?:/(?:[a-zA-Z]|[0-9]|[!*\(\), ]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',a)
>>> share_url
[]
>>>

0 个答案:

没有答案