Regular expression for retrieving a number from a String
Below is the sample code. String X = " Your payment request has been accepted for processing. Your confirmation number for this payment request is : 006993 Please allow up to three business days for this payment to be " final Pattern p = Pattern.compile("(\\s\\d+)"); final Matcher m = p.matcher(x); while(m.find()){ String str1 = m.group().trim(); System.out.println("PPPPPPPPPPPPPPPPP "+str1); } In the above code, we are using 1. class Pattern 2. In class Patter using method compile 3. In the method, use the regular expression "\\s\\d+" (here \\s represents space and \\d represents digits and using + it will retrieve the digit till it ends. If + sign is not used only one digit is displayed). ...