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:
- don't use replaceall (is more complicated in case).
- 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).