Single regular expression for two different strings

I need to write a single regular expression which returns the color value and size values from the below two strings.

[{"id":"2","name":"Color","code":"COLOR","optionValue":{"value":"TANGERINE TANGO","priority":0,"altValue1":"ORANGE","altValue2":null}},{"id":"3","name":"Size","code":"SIZE","optionValue":{"value":"MEDIUM","priority":4,"altValue1":null,"altValue2":null}}]

[{"id":"3","name":"Size","code":"SIZE","optionValue":{"value":"MEDIUM","priority":4,"altValue1":null,"altValue2":null}},{"id":"2","name":"Color","code":"COLOR","optionValue":{"value":"PEACOCK BLUE","priority":0,"altValue1":"GREEN","altValue2":null}}]

Currently I have two different regex for them respectively.

1) COLOR(?:.*?)value":"([^"]+)(?:.*?)SIZE(?:.*?)value":"([^"]+)"
2) SIZE(?:.*?)value":"([^"]+)(?:.*?)COLOR(?:.*?)value":"([^"]+)"

Is there a way I can achieve this using a single regex ?


Source: regex

Leave a Reply