目标:
":method: Put :scheme: http"
替换为
"method: Put scheme: http"
方法
>>> import re
>>> line = ":method: Put :scheme: http"
>>> re.sub(r":\w+", lambda m: f"{m.group()[1:]}", line)
'method: Put scheme: http'
re.match 从头进行查找,找不到就立即返回空
re.search 从全文中进行查找,到结尾还没找到就返回空
参考:
https://www.runoob.com/python/python-reg-expressions.html
https://www.runoob.com/regexp/regexp-syntax.html