import re
m=re.search('(.*?)\s(.*)','RegExr was created by gskinner.com, and is proudly hosted by Media Temple.')
print(m.group())
print(m.group(1))
print(m.group(2))
log='127.0.0.1 user-identifier frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326'
import re
m=re.search("(.*?)\s(.*?)\s(.*?)\s\[([0-9]*\/[A-Z][a-z]*\/[0-9]*).*",log)
print(m.group(1))
print(m.group(2))
print(m.group())
數字: [0-9]
英文: [A-Z][a-z]
next row: \n
white space: \s
any character: .
multiplier: *
end group notifier: ? e.g. (.*?)
escaped character: \ --> catches \ , [ --> catches [
本文通过具体案例展示了正则表达式的使用方法,包括如何匹配特定的字符串模式,如数字、英文字符、换行符等,并通过Python的re模块进行搜索和打印匹配结果。
381

被折叠的 条评论
为什么被折叠?



