[英]how to use a regular expression to achieve the following output?
I am cleaning my data from urls I tried:我正在从我尝试过的网址中清除我的数据:
s = 'hello http://www.google.com I am william http://www.google.com'
from urlparse import urlparse
s.split()
clean = ' '.join([el for el in [i for i in s.split()] if not urlparse(el).scheme])
print(clean)
desired output:所需的输出:
hello I am william
However this time I would like to achieve the same output using instead a regular expression.但是这次我想使用正则表达式来实现相同的输出。
use replacement使用替换
import re
s = 'hello http://www.google.com I am william http://www.google.com'
print(re.sub('http\S+\s?', '', s))
Prints印刷
hello I am william
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.