[英]How to split a string into multiple parts?
I have f = imgString.split('medias/')[1] g = f.split('?')[0] print(g)
but I'd prefer it on one line. 我有f = imgString.split('medias/')[1] g = f.split('?')[0] print(g)
但我更喜欢一行。 How can I split this string into multiple parts 'media/Clearance.png?sometexthere'
.Ideally I'd like just the Clearance.png. 我如何将字符串分成多个部分'media/Clearance.png?sometexthere'
理想情况下,我只需要Clearance.png。 so if I was splitting it it'd be 'media/', 'Clearance.png' and '?sometexthere' 因此,如果我将其拆分,则为“ media /”,“ Clearance.png”和“?sometexthere”
string = 'media/Clearance.png?sometexthere'
string.split("/")[1].split("?")[0]
If it is always the same format you can use regex like this one : ([a-zA-Z]*)\\/(.*)\\?([a-zA-Z]*)
and then with re.group()
you can have all the parts of your string :) 如果总是相同的格式,则可以像这样使用正则表达式: ([a-zA-Z]*)\\/(.*)\\?([a-zA-Z]*)
re.group()
([a-zA-Z]*)\\/(.*)\\?([a-zA-Z]*)
,然后使用re.group()
您可以包含字符串的所有部分:)
You can check it here link ! 您可以在这里查看链接 !
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.