| Free tutorials for Java, Eclipse and Web programming |
Version 0.6
Copyright © 2007 - 2009 Lars Vogel
07.12.2009
| Revision History | ||
|---|---|---|
| Revision 0.1 | 07.12.2007 | Lars Vogel |
| Created list of regex expressions | ||
| Revision 0.2 | 30.12.2008 | Lars Vogel |
| Added Java usage description | ||
| Revision 0.3 | 03.01.2009 | Lars Vogel |
| Re-structured article | ||
| Revision 0.4 | 21.07.2009 | Lars Vogel |
| Clean-up | ||
| Revision 0.5 | 06.12.2009 | Lars Vogel |
| Improved description of qualifiers | ||
| Revision 0.6 | 07.12.2009 | Lars Vogel |
| Re-structured the article | ||
Table of Contents
A regular expression define a search pattern for strings. This pattern may match one or several times or not at all for a given string. The abbreviation for regular expression is "regex".
A simple example for a regular expression is a (literal) string. For example the regex "Hello World" will match exactly the phrase "Hello World". Another example for a regular expression is "." (dot) which matches any single character; it would match for example "a" or "z" or "1".
Regular expressions can be used to search, edit and manipulate text.
Regular expressions are used in several programming languages, e.g. Java but also Perl, Groovy, etc. Unfortunately each language / program supports regex slightly different.
The pattern defined by the regular expression is applied on the string from left to right. Once a source character has been used in a match, it cannot be reused. For example the regex "aba" will match "ababababa" only two times (aba_aba__).
Some of the following examples use JUnit to validate the result. You should be able to adjust them in case if you don't want to use JUnit. To learn about JUnit please see JUnit Tutorial .