[英]how to use a regular expression to achieve the following output?
我正在從我嘗試過的網址中清除我的數據:
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)
所需的輸出:
hello I am william
但是這次我想使用正則表達式來實現相同的輸出。
使用替換
import re
s = 'hello http://www.google.com I am william http://www.google.com'
print(re.sub('http\S+\s?', '', s))
印刷
hello I am william
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.