Matching two sets of numbers from a line. (2.66 and 34.3).
These can digits are variable in length but surrounded by whitespace. eg
Ox 2.66 abcda 34.3 abfdasd
I got 2.66 with \b(?:Ox)\s (\d*\.*?\d )
Any resources that can guide me in the right direction? Im stuck on matching the second separately. cheers
CodePudding user response:
you could write the following regular expression: ([\d\D\s]*).
Let me know!
Bye M
CodePudding user response:
You may continue the regex pattern and capture the second number after another word:
\bOx\s (\d*\.?\d )\s \S \s (\d*\.?\d )
See the regex demo. The second number will be in Group 2.
Details:
\b- a word boundaryOx- a wordOx\s- one or more whitespaces(\d*\.?\d )- Group 1: zero or more digits, an optional., one or more digits\s- one or more whitespaces\S- one or more non-whitespaces\s- one or more whitespaces(\d*\.?\d )- Group 2: zero or more digits, an optional., one or more digits
