/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package salesApplication;

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

/**
 *
 * @author mtthw
 */
public class MatchAPattern {
    
    public static void search(String searchFor, String searchIn){
        System.out.println("Searching for pattern: "+searchFor+" in the text "+searchIn);
        Pattern p = Pattern.compile(searchFor);
        Matcher match = p.matcher(searchIn);
        System.out.println("Result of the search: "+match.find());
    }
    
    public static void main(String[] args) {
        search("Pen","Super Pen");
        search("pen","Super Pen");//do capitals make a difference?
        search("[0-9]","Super Pen2");//Contains a digit (explicit class)
        search("\\d","Super Pen2");//alternative - predefined class
        search("Pen$","Super Pen");//Ends with "Pen"
        search("^Pen","Super Pen");//Starts with "Pen"
        search("^Pen$","Super Pen");//Is an exact match with "Pen" --not this is the equivalent of 'matches'
        search("^.*Pen.*$","Super Pen");//Is an exact match with the pattern ".*Pen.*"
        search("e{2}","Super Pen");//Contains 2 or more e's
        search("e.*e","Super Pen");//Contains 2 or more e's (not necessarily consecutively) 
        search("\\\\","Super \\ Pen");//Contains a '\'
    }
}
