Reputation: 675
public String match(String cadena){
String name = "";
Pattern p = Pattern.compile("\\d");
Matcher m = p.matcher(cadena);
while (m.find()) {
name = name + m.group(0);
}
return name;
}
Please help, I need enter string like this
ej. :USD $ 2300.00
Result:
2300.00
Upvotes: 1
Views: 200
Reputation: 1055
you can also try this pattern: "\\d+\\.?\\d[0-2]"
explanation:
\\d+
- look for 1 or more digits between 0 and 9
\\.?
- there can be a dot, but does not have to be (? = 0 or 1)
\\d[0-2]
- after the dot can be up to 2 digits between 0 an 9
with this pattern you will return 2300.00 from ej. :USD $ 2300.00
Upvotes: 2
Reputation: 675
I just put this to my string:
v.getText().toString().replaceAll("[^\\d.]", "");
Upvotes: 0