300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python截取关键字后的字符串_使用正则表达式获取python中特定字符串之后的所有内容...

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

时间:2018-08-06 13:32:40

相关推荐

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

如果要使用正则表达式,请使用re.findall:re.findall('(?<=com/).*$', "/thedubaimall")

# ['thedubaimall']

一些速度测试有@DeepSpace的建议:%timeit re.findall('(?<=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/(.*)', "/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 "/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的回答快多了。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。