Ask Questions?

View Latest Questions

Advertisement


 
 

Regular Expressions
Posted on: July 26, 2006 at 12:00 AM
Regular expressions are the most common programming technique to search for patterns in strings, extracting, and replacing substrings.

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, ....

They 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.

  • additional String methods. See String Regex Methods.
  • Additional classes, java.util.Pattern and java.util.Matcher, allow use of precompiled regular expressions as well as providing many additional functions. See Pattern and Matcher.

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

Advertisement


DMCA.com