Java: Regular Expressions

Regular expressions are the most common programming technique to search for patterns in strings, extracting, and replacing substrings. They are an essential part of many languages, editors, and utilities, for example, Perl, JavaScript, awk, sed, vi, ....

The are powerful and useful. Simple regexes are simple, but large regexes are extremely difficult to debug. They are often not the right solution for complex parsing problems. Two quotes illustrate some feelings about them. Despite the name, as someone said, Regular expressions are neither regular nor expressions. And Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. Regular expressions form a quirky, error-prone, terse, but useful, programming language for pattern matching.

Java, as of version 1.4, has extensive support for regular expressions in two areas.

Regular expressions provide more general mechanisms for parsing input strings than, eg, StringTokenizer.

Programming language. Regular expressions (often refereed to as regex) are essentially a programming language of their own.

Other Resources