import java.util.regex.*;
/****************************************************************************************************
* Examples: args[0]       args[1]
*           Hell+o        Hello         try( Helllllllo, abcHellloxyz, etc.)
*           \\w+\\s+\\w+  "Sam Sultan"  try(any 2 words separated with one or more spaces)
****************************************************************************************************/
public class regex2 
{
    public static void main(String[] args) 
    {
        if (args.length < 2) {
            System.out.println("Re-execute and enter: args[0] for regex and args[1] for string");
            System.exit(0);
        }
        
        System.out.println("Practice with REGEX: \n");

      //Simple REGEX matching -----------------------------------------------------------

        boolean OK = Pattern.matches( args[0], args[1] );                   //exact full match
        System.out.println("The string fully matches the pattern: " + OK);


      //More complex REGEX matching -----------------------------------------------------

        Pattern p1 = Pattern.compile(args[0], Pattern.CASE_INSENSITIVE);     //Create a Pattern object 

        Matcher m1 = p1.matcher(args[1]);                                    //create a Matcher object
    
        boolean OK2 = m1.find();                                             //call the find() method 
        System.out.println("The string contains the pattern:      " + OK2);  

        if (OK2)
        {
            String found = m1.group();                                       //the text that matched the regex
            System.out.println("The text that matches the regex is:   " + found);   

//          String group1 = m1.group(1);                                     //the first group within parenthesis (if any)
//          System.out.println("The first parenthesis is:        " + group1);
        }           
    }       
}