001package algs54; // section 5.4
002import stdlib.*;
003/* ***********************************************************************
004 *  Compilation:  javac Validate.java
005 *  Execution:    java Validate pattern text
006 *
007 *  Reads in a regular expression and a text input string from the
008 *  command line and prints true or false depending on whether
009 *  the pattern matches the text.
010 *
011 *  % java Validate "..oo..oo." bloodroot
012 *  true
013 *
014 *  % java Validate "..oo..oo." nincompoophood
015 *  false
016 *
017 *  % java Validate "[^aeiou]{6}" rhythm
018 *  true
019
020 *  % java Validate "[^aeiou]{6}" rhythms
021 *  false
022 *
023 *************************************************************************/
024
025public class XValidate {
026
027        public static void main(String[] args) {
028                //args = new String[] { "..oo..oo.", "bloodroot" };
029                //args = new String[] { "..oo..oo.", "nincompoophood" };
030                //args = new String[] { "[^aeiou]{6}", "rhythm" };
031                args = new String[] { "[^aeiou]{6}", "rhythms" };
032
033                String regexp = args[0];
034                String text   = args[1];
035                StdOut.println(text.matches(regexp));
036        }
037
038}