i'm trying write regular expression parse values out of unrealscript serialized objects. part of involves lines this:
(x=32.69,y='123.321',z="a string commas, complicate things!",w=class'some.class')
the resultant capture should be:
[ { 'x':32.69, 'y':'a string commas, complicate things!', 'z':'class\'some.class\' } ]
what want able distinguish between key (eg. x
) , value (eg. class\'some.class\'
).
here pattern i've tried far, capture simple set of values (currently doesn't try handle commas inside values, now):
pattern
\(((\s?)=(.+),?)+\)
data set
(x=32,y=3253,z=12.21)
result
https://regex101.com/r/gt9uu3/1
i'm still novice these regular expressions , appreciated!
thanks in advance.
you can try regex associate key , value pairs:
(?!^\()([^=,]+)=([^\0]+?)(?=,[^,]+=|\)$)
explaining:
(?!^\() # not match initial '(' character ([^=,]+) # match key .. take last comma = # till next '=' character ([^\0]+?) # combination '[^\0]' - key's value # @ least 1 digit '+' # stops in first occurrence '?' (?= # occurrence? ,[^,]+= # comma ',' , key '[^,]+=' # important: without key: # occurrence stop in first comma # should or should not delimiter-comma |\)$ # or '|': value can last 1 # has not key in sequence, # so, must accept value # ends '$' in ')' character ) #
hope helps.
sorry english, feel free edit explanation, or let me know in comments. =)
Comments
Post a Comment