python截取关键字后的字符串_使用正则表达式获取python中特定字符串之后的所有内容...
如果要使用正則表達(dá)式,請使用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的建議快了一點(diǎn),@Kevin的回答快多了。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎總結(jié)
以上是生活随笔為你收集整理的python截取关键字后的字符串_使用正则表达式获取python中特定字符串之后的所有内容...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python爬取b站弹幕_爬取B站弹幕并
- 下一篇: php上下属对应关系,由主分类 ID 取