How to apply filter here
String x=Showing 138 of 138 String(s)
i want to get only 138, ending value how to get that?
How to apply filter here
String x=Showing 138 of 138 String(s)
i want to get only 138, ending value how to get that?
You can try :
public static void main(String[] args) throws IOException {
String x="Showing 158 of 138 String(s)";
System.out.println(x.replaceAll(".*\\s(\\d+).*", "$1"));
}
O/P : 138
I would not use regex for this as it won't be flexible solution. Try Paring the string to get valid value:
String s =" String x=Showing 138 of 138 String(s)";
String[] words = s.split(" ");
BigDecimal value = null;
for(String word : words) {
try {
value = BigDecimal.valueOf(word);
} catch(NumberFormatException e) {}
}
System.out.println(value);