This is my string: 50.00.00..00.00
I want to match all .
except the last one, so after a replace I end up with 50000000.00
\.(?=.*\.)
Matches a dot (\.
), which there must be another dot following it ((?=.*\.)
).
(This assumes the regex engine supports lookahead, e.g. PCRE, Python, etc.)
So you did not specified your regex tools, engine, etc. Well you can do this with e.g. sed
(only work if there are always two digits after the last dot
and the last dot
is always present):
echo "50.00.00..00.00" | sed 's/\.//;s/\(..\)$/.\1/'
But there are several other ways, e.g. with lookahead regex (if it's supported for you).
HTH