I've got a problem with a regex, I need to extract a string from text and keep whitespace, coma and dot in the number(if it is exists), example: Lorem impsum the price is:196 000,2545.20 $ blablabla,
Output:
196 000,2545.20
Example2:2530002545.20 £,
Output:
2530002545.20
I did the following:
String exampleStr = "Lorem impsum the price is:196 000,2545.20 $ blablabla"
String result = exampleStr.replaceAll("[^\\d.,]", " ")
.replaceAll(/\s*$/,'')
Firstly replace everything that is not whitespace, comma, dot or whitespace(to keep it in the number), secondly removed spaces from the end of the string. This solution works, BUT I want to re-do it in a more proper way, to keep that white space inside and remove others from the beginning and the end of the 'price'. Ps: I really don't understand how to combine these two regexes, looking forward to your answers. Peace!