I’m trying to convert $(5.20) to -5.20 using regular expressions, but can’t seem to figure out how to use regular expressions. Could someone please help me to resolve this issue? I need to remove the dollar sign and only accept digits with a maximum of 1 decimal point ie do not accept 5.2.0, but only 5.20. Also, the $ at the beginning is optional and there could be multiple $ as well.
Example of what I started with:
^\((\d)*\)$ - does not work
-$1
Try this regex
Your replacement should already be fine. This regex expects at least one digit before and after the decimal point.
The problem with your regex is, that it will only match if there is no decimal point at all. Also you don’t check for the
$character. And lastly, if this$(5.20)is not your full string, than you should leave out the anchors at the beginning and at the end:If you want to match numbers without decimal points, too, then you can make the dot and the second repetition optional: