Regex Operation to Extract html Strings

Viewed 32

I have the following html code:

'"height": { "@type": "QuantitativeValue", "value": "6-1" },\n    
"weight": {"@type": "QuantitativeValue", "value": "195 lbs" }\n}\n'

I want to create a Regex that'll extract the height and weight values (6-1 and 195 lbs). What re expression can do this?

1 Answers

If you don't have anything else with the pattern "value": "", then just use:

value":\s"?(.*)"

https://regex101.com/r/clWVkg/1

If you do, then you can specify that you only want the values from height and weight caught:

(height|weight).*"value":\s"?(.*)"

https://regex101.com/r/5ShdKO/1

This will check for the word height or weight first, then ignore everything until value before doing a lazy catch all to capture the value. You should be able to extract the value by extracting the group.

Related