MainClass.java Source code

Java tutorial

Introduction

Here is the source code for MainClass.java

Source

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

public class MainClass {
    public static void main(String args[]) {
        // create a Pattern
        Pattern p = Pattern.compile("Bond");

        // create a Matcher and use the Matcher.group() method
        String candidateString = "My name is Bond. James Bond.";
        Matcher matcher = p.matcher(candidateString);
        // extract the group
        matcher.find();
        System.out.println(matcher.group());
    }
}