Regular expressions (as in Unix grep, Perl, Javascript, XML schemas) are used in java.util.regex. Eg, to find the distinct values of all class attributes used in an HTML file:
StringBuffer sb = new StringBuffer (htmlFileContents);
java.util.Map classes = new HashMap (); // Maps are covered later in this course
java.util.regex.Pattern p =
java.util.regex.Pattern.compile (" class\\s*=\\s*\"(.*?)\"");
java.util.regex.Matcher m = p.matcher (sb);
while (m.find ())
{
String htmlClass = m.group (1);
classes.put (htmlClass, htmlClass);
} // NB: keys are not duplicated
The syntax of regular expressions would be another course!
For text pattern matching, also be aware of String.split (), java.util.StringTokenizer, java.io.StreamTokenizer