I have: "The price is 1 000$ another pice 34 000 , 00 EUR. You have to pay 1400 EUR, and you have to pay extra 2000$"
. What i want? I want price, but if before price is word "pay" or "pay extra" then i must reject this price. I have regex that give me price, so it is great, but i think that i need another? or modify regex that reject some price if before price is specific word. Output of my example should be: 1000,34000
My code:
String regex = "(([0-9]+[\\s,.]*)+)(\\$|EUR)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
price = matcher.group();
if (price.contains(",")) {
price = price.substring(0, price.indexOf(","));
}
price = price.replaceAll("\\s", "").replaceAll("[^0-9]+", "");
if (price.contains(",")) {
price = price.replaceAll("\\,", "");
} else {
price = price.replaceAll("\\.", "");
}
It give me:
1000,34000,1400,2000
But I want only: 1000,34000
I must reject these prices that are after word "pay" and "pay extra".
edit: "." is for price like this 1 000. 00