python截取关键字后的字符串_使用正则表达式获取python中特定字符串之后的所有内容...
如果要使用正則表達式,請使用re.findall:re.findall('(?<=com/).*$', "www.example.com/thedubaimall")
# ['thedubaimall']
一些速度測試有@DeepSpace的建議:%timeit re.findall('(?<=com/).*$', "www.example.com/thedubaimall")
# The slowest run took 7.57 times longer than the fastest. This could mean that an intermediate result is being cached.
# 1000000 loops, best of 3: 1.29 μs per loop
%timeit re.findall('com/(.*)', "www.example.com/thedubaimall")
# The slowest run took 6.48 times longer than the fastest. This could mean that an intermediate result is being cached.
# 1000000 loops, best of 3: 992 ns per loop
%timeit "www.example.com/thedubaimall".partition(".com/")[2]
# The slowest run took 7.87 times longer than the fastest. This could mean that an intermediate result is being cached.
# 1000000 loops, best of 3: 204 ns per loop
看起來,@DeepSpace的建議快了一點,@Kevin的回答快多了。
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的python截取关键字后的字符串_使用正则表达式获取python中特定字符串之后的所有内容...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬取b站弹幕_爬取B站弹幕并
- 下一篇: python怎么模拟浏览器交互_干货分享