I'm trying to parse weight, depth and height from the following string using regex '84" w x 39" d x 37" h'. I got success while scooping out weight and depth for it. However, I could not scrape the height in the right way. I know the patterns I've used might be very weak but it works for the first two fields.
I've tried with:
import re
rstr = '84" w x 39" d x 37" h'
weight = re.findall(r"(.*?)\"\s*?w",rstr)[0]
depth = re.findall(r"x\s*(.*?)\"\s*?d",rstr)[0]
height = re.findall(r"x\s*(.*?)\"\s*?h",rstr)[0]
print(weight,depth,height)
Output I'm getting:
84 39 39" d x 37
Output I wish to get:
84 39 37
The weight, depth and height may not always be in the same order.
How can I scrape the three fields from the above string using regex?
..x\s*(\d+(?:\.\d+)?)"?\s*h, see demo.\b(\d+)" \w x (\d+)" d x (\d+)" h\bregex101.com/r/02EQNV/1 to get all of them in a single pattern and then use the groups