CIT597 Quiz 4 (Regex)
Fall, 2007
Name_________________________________________

Please keep all answers short and to the point. Read each question and answer it; don't add information that wasn't asked for.

  1. (50 points) Tell, in words, what each of the following patterns will match.

    1. a+


    2. abc+



    3. \s*



    4. [0-9]



    5. [^aeiou]



    6. .*



    7. (fish|fowl)



    8. </[^>]>



    9. [a-z_A-Z][a-z_A-Z0-9]+



    10. (\d*\.\d+)|(\d+\.\d*)



  2. (15 points) There are three ways you can use a regular expression to try to match a string. What are those three ways? (Short answers, please.)








  3. (5 points) Write the regular expression \d+\.\d+ as a Java quoted String.



  4. (15 points) Write the Java statements (not a complete program!) to set a boolean variable b to true if and only if the string s contains a digit.









  5. (5 points) By default, quantifiers are greedy. What does this mean?




  6. (10 points) If you apply the regular expression ([a-z]*)([0-9]+)([a-z]*) to the string abc123xyz

    1. What characters are matched by the second capturing group?


    2. What characters are matched by the zeroth capturing group?