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?
Thank you
SOLUTION leave to posterity the solution: - if you're looking for a simple and effective solution that does not use the regex, see Johnatan post below - if you're looking for a solution using RegEx, see wonderful regex from stribizhev
R"((?:^|\s)([+-]?[[:digit:]]+(?:\.[[:digit:]]+)?)(?=$|\s))"
Thanks !!!
Aucun commentaire:
Enregistrer un commentaire