## Regexp

Regexp represents a regular expression.

### Parameters

Attribute | Description | Required
pattern | regular expression pattern | Yes

### Examples

>          <regexp id="myregexp" pattern="alpha(.+)beta"/>

Defines a regular expression for later use with id myregexp.

>          <regexp refid="myregexp"/>

Use the regular expression with id myregexp.

### Choice of regular expression implementation

Ant comes with wrappers for the java.util.regex package of JDK 1.4, jakarta-regexp and jakarta-ORO, See installation dependencies concerning the supporting libraries.

The property `ant.regexp.regexpimpl` governs which regular expression implementation will be chosen. Possible values for this property are :

- org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
- org.apache.tools.ant.util.regexp.JakartaOroRegexp
- org.apache.tools.ant.util.regexp.JakartaRegexpRegexp

It can also be another implementation of the interface `org.apache.tools.ant.util.regexp.Regexp`. If `ant.regexp.regexpimpl` is not defined, ant checks in the order Jdk14Regexp, JakartaOroRegexp, JakartaRegexp for the availability of the corresponding library. The first of these 3 which is found will be used.

There are cross-platform issues for matches related to line terminator. For example if you use $ to anchor your regular expression on the end of a line the results might be very different depending on both your platform and the regular expression library you use. It is 'highly recommended' that you test your pattern on both Unix and Windows platforms before you rely on it.

- Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.
- Jakarta RegExp uses a system-dependant line terminator.
- JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default but is configured in the wrapper to use only '\n' (UNIX_LINE)

We strongly recommend that you use Jakarta Oro.

### Usage

The following tasks and types use the Regexp type :

- ReplaceRegExp task
- LineContainsRegexp filter

These string filters also use the mechanism of regexp to choose a regular expression implementation :

- ContainsRegex string filter
- ReplaceRegex string filter

Copyright © 2003-2004 The Apache Software Foundation. All rights Reserved.