regex count for matching in java

Solutions on MaxInterview for regex count for matching in java by the best coders in the world

showing results for - "regex count for matching in java"
Arsène
04 May 2019
1import java.util.regex.*;
2
3class Test {
4    public static void main(String[] args) {
5        String hello = "HelloxxxHelloxxxHello";
6        Pattern pattern = Pattern.compile("Hello");
7        Matcher matcher = pattern.matcher(hello);
8
9        int count = 0;
10        while (matcher.find())
11            count++;
12
13        System.out.println(count);    // prints 3
14    }
15}