/**
 * BasicRegex - Introduction to regular expressions in Java
 * This example demonstrates how to use Pattern and Matcher to identify patterns.
 *
 * Part III of the book "Introduction to Programming in Java"
 */

import java.util.regex.*;

public class BasicRegex {
    public static void main(String[] args) {
        String text = "I want to learn Java";

        // Checks whether the text contains "Java"
        Pattern pattern = Pattern.compile("Java");
        Matcher matcher = pattern.matcher(text);
        System.out.println("Contains 'Java': " + matcher.find());

        // Checks whether the text starts with "I"
        pattern = Pattern.compile("^I");
        matcher = pattern.matcher(text);
        System.out.println("Starts with 'I': " + matcher.find());

        // Checks whether the text ends with "Java"
        pattern = Pattern.compile("Java$");
        matcher = pattern.matcher(text);
        System.out.println("Ends with 'Java': " + matcher.find());

        // Testing with another text
        text = "Programming in Java is fun";
        pattern = Pattern.compile("Java");
        matcher = pattern.matcher(text);
        System.out.println("Contains 'Java' in the new text: " + matcher.find());
    }
}
