-1

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?

sameer joshi
  • 377
  • 2
  • 8
  • 27

2 Answers2

1

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

TheLostMind
  • 35,966
  • 12
  • 68
  • 104
0

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);
agilob
  • 6,082
  • 3
  • 33
  • 49