How to use regular expression to extract string separated by spaces?
My sample string is
"Used 1908 Honda 123 Test Coupe"
I want to extract substrings ("Used", "1908", "Honda", "123", "Test" and "Coupe") from the above string using regex. How to use the regex for same?
Regex isn’t always the answer. Depending on the programming language you use, you’d be better off splitting your string.
Say you have python, you can do something as simple as:
text = "Used 1908 Honda 123 Test Coupe" parts = text.split(" ")
However, if you absolutely must, here’s the simplest regex for your purpose:
It simply matches anything that’s a word character (whish is a-z, A-Z, and 0-9) and is repeated once or more. It neatly excludes all whitespaces.
Answered By – M.H. Tajaddini