Answers for "regex count for matching in java"

0

regex count for matching in java

import java.util.regex.*;

class Test {
    public static void main(String[] args) {
        String hello = "HelloxxxHelloxxxHello";
        Pattern pattern = Pattern.compile("Hello");
        Matcher matcher = pattern.matcher(hello);

        int count = 0;
        while (matcher.find())
            count++;

        System.out.println(count);    // prints 3
    }
}
Posted by: Guest on September-26-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language