Python正则表达式:如何拆分webpubsubscriptionbillmeclientsapi3.0.14.1。

2024-04-25 19:38:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我想分开 webs-pub-subscription-billme-clients-api-3.0.14.1.war

收件人:

Web pub订阅billme客户端api

以及 3.0.14.1条

如何在Python中进行拆分?谢谢


Tags: apiweb客户端收件人subscriptionclientspubwebs
2条回答

就这样好了:

import re
regex = r"(-)(?=[\d\.]+)"
test_str = "webs-pub-subscription-billme-clients-api-3.0.14.1.war"
subst = " "
result = re.sub(regex, subst, test_str, 0)
if result:
    print (result)
s = 'webs-pub-subscription-billme-clients-api-3.0.14.1.war'

# slice between the last dash, and the last dot:
print s[s.rfind('-')+1:s.rfind('.')]


# or, regex split on the last dash or the last dot 
# (a dash not followed by another dash, or a dot not followed by another dot)
# and take the middle chunk
import re
print re.split('-(?!.*-)|\.(?!.*\.)', s)[1]

Try online at Repl.it

相关问题 更多 >