日常正则

各位有好的常用样例,也可以评论回复噢,看到了,会更新到随笔里,期待共同创建美好码园

在线正则表达式测试地址

匹配指定字符串之前的数据

.*=
update receipt_header set returnWaybillCode='JDVE04111322979' WHERE warehouseCode='WH-TIANJIN' AND receiptType='THRK' AND sourceOrderCode='RK202201041833220001';

匹配指定字符串之间的数据

update.*=
update receipt_header set returnWaybillCode='JDVE04111322979' WHERE warehouseCode='WH-TIANJIN' AND receiptType='THRK' AND sourceOrderCode='RK202201041833220001';

取出域名后面的所有数据

import re

url = "https://api.zhihu.com/questions/48908741"
result = re.search(r'https://[^/]+/(.*)', url).group(1)
print(result)
# 输出 questions/48908741

取出域名带http[s]

import re

pattern = re.compile(r'http[s]?://(.+?)/')

url = "https://api.zhihu.com/questions/48908741"
yumm = pattern.search(url).group()
print(yumm)
# 输出 https://api.zhihu.com/

只取出域名

import re

# 取出域名信息
pattern = re.compile(r'http[s]?://(.+?)/(.*)')
url = "https://www.zhihud.com/search?type=content&q=WMS"

result = pattern.search(url).group(1)
print(result)
# 输出 www.zhihud.com/

匹配IP端口后面的数据

import re

ip_port = re.compile(r'http[s]?://(?:(?:[0,1]?\d?\d|2[0-4]\d|25[0-5])\.){3}(?:[0,1]?\d?\d|2[0-4]\d|25[0-5]):\d{0,5}/')
aa = ip_port.sub("", 'http://127.0.0.1:768/asdaff/dasfa?sdaf&fas')

print(aa)
# 输出 asdaff/dasfa?sdaf&fas
posted @ 2022-01-06 18:46  darling331  阅读(33)  评论(0编辑  收藏  举报