G
G
germantoogood2020-05-21 17:24:11
Regular Expressions
germantoogood, 2020-05-21 17:24:11

Regular expression to search for key-value pairs?

You need to get the result:
Weight: About 17 lbs
Color: Black
Load capacity: 263 lbs
Tested for: 120-150 kg (263-330 lbs) dynamic state
etc

from the line:
Weight: About 17 lbs Color: Black Load capacity: 263 lbs Tested for: 120-150 kg (263-330 lbs) dynamic state Overall dimension: 22.5" x 21.5" x 35"- 39" (L x W x H) Backrest size:17.5" x 19" Seat size:17.5" x 17.5 " Adjustable chair seat: 18"-22"
As I understand one pair: [a word with a capital letter (or a word with a capital letter and several with a small one)][:][something up to the next key of the same type:]
Got the keys so far, regex:
[AZ][az]*(\s[az]*)*[:]
5ec68d5c801ee616922305.png
How to get all key-value matches?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dodo512, 2020-05-21
@germantoogood

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

([A-Z][a-z]*(?:\s[a-z]*)*):(.*?)(?=$|[A-Z][a-z]*(?:\s[a-z]*)*:)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question