What are regular expressions? A regular expression, also known as a regex or regexp, is a string whose
pattern (template) describes a set of strings. The pattern determines what strings belong to the set, and consists of literal characters and metacharacters, characters that have special meaning instead of a literal meaning. The process of searching text to identify matches�strings that match a regex's pattern�is pattern matching.
Java's java.util.regex package supports pattern matching via its Pattern, Matcher, and PatternSyntaxException classes:
Pattern objects, also known as patterns, are compiled regexes
Matcher objects, or matchers, are engines that interpret patterns to locate matches in character sequences, objects whose classes implement the java.lang.CharSequence interface and serve as text sources
PatternSyntaxException objects describe illegal regex patterns
Code example Run java RegexDemo apple
applet Result
Regex = apple
Text = applet
Found apple
starting at index 0 and ending at index 5
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand