0

I have regex wich split text such USD88 in two groups - USD and 88

  ([a-zA-Z]+)(\d+.?\d*)

But in Java I can't get last group. Java code excerpt:

        Pattern pattern = 
        Pattern.compile("([a-zA-Z]+)(\\d+.?\\d*)");

        System.out.println("Enter input string to search: ");
        Matcher matcher = 
        pattern.matcher(bufferedReader.readLine());

        while (matcher.find()) {
            for(int i=0;i<matcher.groupCount();i++) {
                 System.out.format("capture group " +i+
                         " \"%s\" starting at " +
                         "index %d and ending at index %d.%n",
                         matcher.group(i),
                         matcher.start(i),
                         matcher.end(i));
            }
        }

Example:

 Enter input string to search: 
 USD100
 capture group 0 "USD100" starting at index 0 and ending at index 6.
 capture group 1 "USD" starting at index 0 and ending at index 3.
 Enter input string to search: 
 USD55.7
 capture group 0 "USD55.7" starting at index 0 and ending at index 7.
 capture group 1 "USD" starting at index 0 and ending at index 3.

0 Answers0