I'm looking for a regex to find numbers in a string; if I have a string like:
li 12.12 si 43,23 45 31 uf 889 uf31 3.12345
I want to find only the numbers:
12.12 45 31 889 3.12345
I tried with the following pattern:
((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?
but the output included uf31
and 43,23
.
I tried with:
(?!([a-z]*((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?[a-z]*))?((\\+|-)?[[:digit:]]+)(\\.(([[:digit:]]+)?))?
but this gave the same result.
What is the solution?
SOLUTION leave to posterity the solution:
- If you're looking for a simple and effective solution that does not use the regex, see Jonathan Mee's post below
If you're looking for a solution using RegEx, see the wonderful regex from stribizhev
R"((?:^|\s)([+-]?[[:digit:]]+(?:\.[[:digit:]]+)?)(?=$|\s))"