![](/img/trans.png)
[英]Finding a single quote after an equal sign in a string using regex python
[英]split string with equal sign at any location using python
我想在任何位置分割等号的字符串。
[In] This is a example string abc=xyz this is a example string
有人可以告诉我如何在等于号(“ =”)之后打印所有字符串。 例如,在上述情况下,输出应为
[Out] abc=xyz
我有一些线索可以断定if('=')是否在最后一个单词中而不是在字符串内部的任何位置。
findall查找所有事件,(我认为那是您的要求)
import re
a = "[In] This is a example string abc=xyz this is a example string"
print(re.findall("\w+=\w+",a))
OP
['abc=xyz']
s='This is a example string abc=xyz this is a example string'
l=s.split('=')
print(l)
输出:
['This is a example string abc', 'xyz this is a example string']
因此,您希望l[-1]
获得最后一项或l[1]
获得第二项
编辑:如果您想找到其中有一个=
的“单词”
s='This is a example string abc=xyz this is a example string'
l=s.split()
l = [word for word in l if '=' in word]
print(l)
输出:
['abc=xyz']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.