2024-04-25 17:56:27 发布
网友
这似乎是一个非常简单的问题,但这花了我几个小时:
mystr='link/123' pattern = re.compile(r'123') print(pattern.match(mystr))
结果是None。 我知道,“/”只是一个普通的字符,我不知道为什么re不起作用
None
re
match将只在字符串开头匹配
match
https://docs.python.org/3/library/re.html#re.regex.match
改用search
search
https://docs.python.org/3/library/re.html#re.regex.search
match
将只在字符串开头匹配https://docs.python.org/3/library/re.html#re.regex.match
改用
search
https://docs.python.org/3/library/re.html#re.regex.search
相关问题 更多 >
编程相关推荐