MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

/*
 * Output:
Match: www
Match: java
Match: s
Match: com
    
 * */

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

public class MainClass {
    public static void main(String args[]) {
        // Match lowercase words.
        Pattern pat = Pattern.compile("[a-z]+");
        Matcher mat = pat.matcher("www.java2s.com.");

        while (mat.find())
            System.out.println("Match: " + mat.group());
    }
}