0

I am having a string of this type :

String price="$34.56 - $98.45" or it can be simply "$34.56"

I want to convert this string to 34.56-98.45 and 34.56 respectively.

Whats best and easiest way to do it in Java . I was trying for some regex but could not come up.

GitCoder
  • 121
  • 2
  • 13

1 Answers1

0

You can try with this regex:

String val=price.replaceAll("[^\\P{Punct}-.]+", "");
//[^\\P...] (negated character class of characters not having the property)
Madushan Perera
  • 2,568
  • 2
  • 17
  • 36