Validate.java


Below is the syntax highlighted version of Validate.java from §5.4 Regular Expressions.


/******************************************************************************
 *  Compilation:  javac Validate.java
 *  Execution:    java Validate pattern text
 *  Dependencies: StdOut.java
 *  
 *  Reads in a regular expression and a text input string from the
 *  command line and prints true or false depending on whether
 *  the pattern matches the text.
 *
 *  % java Validate "..oo..oo." bloodroot
 *  true
 *
 *  % java Validate "..oo..oo." nincompoophood
 *  false
 *
 *  % java Validate "[^aeiou]{6}" rhythm
 *  true
 *
 *  % java Validate "[^aeiou]{6}" rhythms
 *  false
 *
 ******************************************************************************/

public class Validate { 

    public static void main(String[] args) { 
        String regexp = args[0];
        String text   = args[1];
        StdOut.println(text.matches(regexp));
    }

}


Copyright © 2000–2017, Robert Sedgewick and Kevin Wayne.
Last updated: Fri Oct 20 12:50:46 EDT 2017.