RegularExpressions < Javapedia < TWiki

TWiki . Javapedia . RegularExpressions

Home | Help | Changes | Index | Search | Go

RegularExpressions

Regular expressions are common in many programming languages and Unixish utilities and provide a way to describe the format of text strings. You can write a pattern and then see if a string matches it, or look for all matches, or replace them all with something else, and so on. Here is an example of a regular expression matching typical (but not all) HTTP URLs with optional query strings and fragments:

http://([a-z0-9-]+\.)+[a-z0-9-]+/[^\s#?]*(\?[^\s?#)+?(#[^\s?#)+?

Regex Implementations

J2SE 1.4 supports regular expressions natively in the java.util.regex package. For earlier versions of Java, or for more choices, you can use:

A comparison of the above libraries is available here http://www.oreilly.com/catalog/regex2/chapter/ch08.pdf

JUnit tests for regexes

Please leave a note on the H&P Open Source Wiki

Also See

Mastering Regular Expressions by Jeffrey Friedl at http://www.oreilly.com/catalog/regex2/ is a good introduction and covers advanced usage, including Java (this chapter is available online).

Java Regular Expressions: Taming the java.util.regex Engine by Mehran Habibi at http://www.apress.com/book/bookDisplay.html?bID=177 for complete coverage of the java regex package.



Discussion about RegularExpressions

----- Revision r11 - 31 Jul 2007 - 12:06:26 - Main.scolebourne