import re
result = re.match("[\\.]+[\d]+", "...........................................761")
if result is None:
print(result)
else:
print("success")
当我执行如上程序时,匹配成功了。
import re
result = re.match("[\\.]+[\d]+", " ...........................................761")
if result is None:
print(result)
else:
print("success")
当我执行如上程序时,字符串前面多了个空格,却匹配失败了。
import re
result = re.match("[\\.]+[\d]+", "first chapter...........................................761")
if result is None:
print(result)
else:
print("success")
当我执行如上程序时,字符串前面多了个单词,却匹配失败了。
各位大佬,为啥会匹配失败呀?(正则比较菜,大家轻喷)
1
Inn0Vat10n 2023-09-10 23:43:45 +08:00
[If zero or more characters at the beginning of string match the regular expression pattern, return a corresponding Match]( https://docs.python.org/3/library/re.html#:~:text=If%20zero%20or%20more%20characters%20at%20the%20beginning%20of%20string%20match%20the%20regular%20expression%20pattern%2C%20return%20a%20corresponding%20Match)
|
2
NoOneNoBody 2023-09-10 23:45:17 +08:00 1
match 是从头开始匹配,从中间开始匹配用 re.search
|