I have a string that can vary but will always contain x={stuffNeeded}
.
For example: n=1,x={y,z,w},erore={3,4,5}
or x={y,z,w}
or erore={3,4,5},x={y,z,w}
etc.
I am having a devil of a time figuring out how to get y,z,w
. The closest I got to finding the answer was based off of Yatharth's answer on this other post Regular expression to return all characters between two special characters.
It my searching I've so far come across something that almost worked. Testing was done here http://rubular.com/r/bgixv2J6yF and in python.
This was tested in python using:
i='n=1,x={y,z,w},erore={3,4,5}'
j='n=1,x={y,z,w}'
print re.search('x={(.*)}',i).group(1)
print re.search('x={(.*)}',j).group(1)
print re.search('x={(.*)}.',i).group(1)
print re.search('x={(.*)}.',j).group(1)
Result for the four different print:
'y,z,w'
'y,z,w},erore={3,4,5'
AttributeError: 'NoneType' object has no attribute 'group'
'y,z,w'
Needed result is 'y,z,w'
for all cases and then if x={*}
really isn't found I would put an error catch.
Thank you in advance.