Regular expressions


A regular expression is a String that describes a pattern; the pattern may be applied to another string, to determine if it matches the pattern, or to find and/or replace parts of that other string.

While regular expressions are an advanced topic, the beginner should be aware of two important facts about them:

Regular expressions have quite a complex syntax that is outside the scope of these pages. Details are given in the Java API for java.util.regex.Pattern.

Regular expressions are very powerful, and should be a part of every programmer's toolbox.

However, regular expressions that use characters with special meanings can be extraordinarily inefficient. Any use of such regular expressions should be tested to determine not only their results, but also the sequence of operations performed in order to return those results. Often, very minor changes in a regular expression can have major consequences for efficiency.