I have a string like
String test="top 10 products";
String test2="show top 10 products";
Is there a way to check if the word "top" has a number following it. If yes get that number to another string.
I'm thinking to use indexOf("top") and add 4 to that and try to get the next word. Not sure how it will work. Any suggestions?
Anonymous User
10-Dec-2015Pattern pat = Pattern.compile("top\\s+([0-9]+)");Matcher matcher = pat.matcher("top 10 products or top 20 products");
while (matcher.find()) {
System.out.println(matcher.group(1));
}