def GetPart(s,part=1):
out = s.split('=')[part].strip() #only '=', spaces will be removed
return out
>>> s = 'abcd=efgh'
>>> GetPart(s)
>>> 'efgh'
>>> s = 'abcd= efgh' #note extra spaces
>>> GetPart(s)
>>> 'efgh'
>>> s = 'abcd = efgh ' #even more space before/after
>>> GetPart(s)
>>> 'efgh'
您不需要regex,只要
split()
它:或者:
^{pr2}$您也可以使用此选项:
当然还有:
^{pr2}$您可以使用^{} :
这在您需要的数据中有另一个等号时很有用。在
相关问题 更多 >
编程相关推荐