正则表达式的简单情况练习

在网页中取出图片网址:

re.search(r"http.+?\.jpg",s).group()

提取域名前面的网址:s = https://blog.csdn.net/wangshuai33/article/details/82963081

re.sub(r"(http://.+?/).*",lambda x: x.group(1),s)

'https://blog.csdn.net/'

一个句子里找出所有单词:s = "swfk wfhweu efee"

re.split(r" +",s)

["swfk wfhweu efee"]

re.findall(r"\b[a-zA-Z]+\b",s)

["swfk wfhweu efee"]

猜你喜欢

转载自blog.csdn.net/wangshuai33/article/details/82963190