Regular Expressions in JDK 1.4
The entire regular expression support is contained in the package java.util.regex and is made up of the following two main classes:
java.util.regex.Pattern
An instance of this class is a compiled representation of a regular expression in a string form.
java.util.regex.Matcher
A searcher that performs text match operations by interpreting Pattern on a String of readable characters.
A typical implementation of text searching and/or manipulation using the java.util.regex package is divided into three steps.
Compile the regular expression into an instance of Pattern
Use the Pattern object to create a Matcher object.
Use the Matcher object to search and/or manipulate the character sequence
A typical invocation sequence might be like the example to follow, which uses a regular expression to match 'cats', followed by any number of characters, followed by 'dogs':
Pattern pat=Pattern.compile("cats.*dogs");
Matcher matcher=pat.matcher("cats and dogs");
boolean flag=matcher.matches();