正则表达式中的findall
import repattern = r'(\.{1,3}){3}'
str1 = '127.0.0.1 192.168.1.66'
match = re.findall(pattern,str1)
print(match)
为什么这串代码输出的为
['.1', '.66']
不应该是[''.0.0.1','.168.1.66'] 吗求大佬解释下{:9_221:} {:9_221:} findall 只会获取分组里面的内容:
import re
pattern = r'((\.{1,3}){3})'
str1 = '127.0.0.1 192.168.1.66'
match = re.findall(pattern,str1)
print(match) import re
pattern = r'(?:\.{1,3}){3}'
str1 = '127.0.0.1 192.168.1.66'
match = re.findall(pattern,str1)
print(match)
页:
[1]