J
Jon
I'm trying to match these kinds of malformatted xml tags. I'm beginning
to question my sanity, so i'm posting here.
Example Strings:
=====
A=" <orderMsg biz=0>"
B=" <orderMsg type=7 size=0>"
C=" <orderMsg type=7 size=0 biz=1>"
=====
I've come up with this regex:
=====
/<(\w+?)(?:\s(\w+)=(\w+))+>/
=====
But when matching string B from above:
=====
md=/<(\w+?)(?:\s(\w+)=(\w+))+>/.match(B)
=====
It will do this:
======
md[0]=<orderMsg type=7 size=0>
md[1]=orderMsg
md[2]=size
md[3]=0
nil
nil
nil
nil
=======
Why isn't the final + sign making the pattern "(?:\s(\w+)=(\w+))"
repeat?
As an exercise... /<(\w+?)(?:\s(\w+)=(\w+))(?:\s(\w+)=(\w+))>/ DOES
match String B from above. What the heck???
to question my sanity, so i'm posting here.
Example Strings:
=====
A=" <orderMsg biz=0>"
B=" <orderMsg type=7 size=0>"
C=" <orderMsg type=7 size=0 biz=1>"
=====
I've come up with this regex:
=====
/<(\w+?)(?:\s(\w+)=(\w+))+>/
=====
But when matching string B from above:
=====
md=/<(\w+?)(?:\s(\w+)=(\w+))+>/.match(B)
=====
It will do this:
======
md[0]=<orderMsg type=7 size=0>
md[1]=orderMsg
md[2]=size
md[3]=0
nil
nil
nil
nil
=======
Why isn't the final + sign making the pattern "(?:\s(\w+)=(\w+))"
repeat?
As an exercise... /<(\w+?)(?:\s(\w+)=(\w+))(?:\s(\w+)=(\w+))>/ DOES
match String B from above. What the heck???