Regex for currency in Java string.replaceAll() (not php, not javascript) -


i'm trying prices text in java, i'm usign regex i can't rid of 113:

string str="jañlskd f añlksdj fñlaks: 19,05€ | jfañlskdjf: 22€ jañlsdkf dkjfls 113: 15€ jñalkdf dk añldf: añlkdsj fdlkf dlkfajs 19,05€ buy"; str.replaceall("[^0-9+€|^0-9+,0-9+€|^ ]",""); 

result is:

19,05€ | 22€ 113 15€ 19,05€

i want dismiss numbers no € @ end too.

what i'm doing wrong? thanks

the full answer question is:

  1. don't use replaceall (is more complicated in case).
  2. use matcher find positive matches.

example:

pattern p = pattern.compile("[0-9]+(?:,[0-9]+)?(?=€)"); matcher m=p.matcher(nodevalue); string res=new string(); while (m.find()) {     res+=m.group()+" "; } string prices=res.split(" "); 

thanks (specially hamza).


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -