Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static void main(String[] args) {
        String hello = "HelloxxxHelloxxxHello"; // String you want to 'examine'
        Pattern pattern = Pattern.compile("Hello"); // Pattern string you want to be
                                                    // matched
        Matcher matcher = pattern.matcher(hello);

        int count = 0;
        while (matcher.find()) {
            count++; // count any matched pattern
        }
        System.out.println(count);
    }
}