日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python截取关键字后的字符串_使用正则表达式获取python中特定字符串之后的所有内容...

發布時間:2023/12/9 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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中特定字符串之后的所有内容...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。