def a = ' $ 2 187.00'
a.replaceAll(/\s/,"").replaceAll(/\$/,"")
// or simply
a.replaceAll(/[\s\$]/,"")
It should return 2187.00
.
Note
- that
$
has special meaning in double quoted strings literals""
, called asGString
. - In groovy, you can user regex literal, using that is better than using regex with multiple escape sequences in string.