[14982] | 1 | <!--
|
---|
| 2 | Licensed to the Apache Software Foundation (ASF) under one or more
|
---|
| 3 | contributor license agreements. See the NOTICE file distributed with
|
---|
| 4 | this work for additional information regarding copyright ownership.
|
---|
| 5 | The ASF licenses this file to You under the Apache License, Version 2.0
|
---|
| 6 | (the "License"); you may not use this file except in compliance with
|
---|
| 7 | the License. You may obtain a copy of the License at
|
---|
| 8 |
|
---|
| 9 | http://www.apache.org/licenses/LICENSE-2.0
|
---|
| 10 |
|
---|
| 11 | Unless required by applicable law or agreed to in writing, software
|
---|
| 12 | distributed under the License is distributed on an "AS IS" BASIS,
|
---|
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
| 14 | See the License for the specific language governing permissions and
|
---|
| 15 | limitations under the License.
|
---|
| 16 | -->
|
---|
| 17 | <html>
|
---|
| 18 |
|
---|
| 19 | <head>
|
---|
| 20 | <meta http-equiv="Content-Language" content="en-us">
|
---|
| 21 | <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
|
---|
| 22 | <title>Regexp Type</title>
|
---|
| 23 | </head>
|
---|
| 24 |
|
---|
| 25 | <body>
|
---|
| 26 |
|
---|
| 27 | <h2><a name="regexp">Regexp</a></h2>
|
---|
| 28 | <p>
|
---|
| 29 | Regexp represents a regular expression.
|
---|
| 30 | <h3>Parameters</h3>
|
---|
| 31 | <table border="1" cellpadding="2" cellspacing="0">
|
---|
| 32 | <tr>
|
---|
| 33 | <td valign="top"><b>Attribute</b></td>
|
---|
| 34 | <td valign="top"><b>Description</b></td>
|
---|
| 35 | <td align="center" valign="top"><b>Required</b></td>
|
---|
| 36 | </tr>
|
---|
| 37 | <tr>
|
---|
| 38 | <td valign="top">pattern</td>
|
---|
| 39 | <td valign="top">regular expression pattern</td>
|
---|
| 40 | <td valign="top" align="center">Yes</td>
|
---|
| 41 | </tr>
|
---|
| 42 | </table>
|
---|
| 43 |
|
---|
| 44 | <h3>Examples</h3>
|
---|
| 45 | <blockquote><pre>
|
---|
| 46 | <regexp id="myregexp" pattern="alpha(.+)beta"/><br>
|
---|
| 47 | </pre></blockquote>
|
---|
| 48 | <p>
|
---|
| 49 | Defines a regular expression for later use with id myregexp.
|
---|
| 50 | </p>
|
---|
| 51 | <blockquote><pre>
|
---|
| 52 | <regexp refid="myregexp"/><br>
|
---|
| 53 | </pre></blockquote>
|
---|
| 54 | <p>
|
---|
| 55 | Use the regular expression with id myregexp.
|
---|
| 56 | </p>
|
---|
| 57 | <h3><a name="implementation">Choice of regular expression implementation</a></h3>
|
---|
| 58 | <p>
|
---|
| 59 | Ant comes with
|
---|
| 60 | wrappers for
|
---|
| 61 | <a href="http://java.sun.com/j2se/1.4/docs/api/java/util/regex/package-summary.html" target="_top">the java.util.regex package of JDK 1.4</a>,
|
---|
| 62 | <a href="http://jakarta.apache.org/regexp/" target="_top">jakarta-regexp</a>
|
---|
| 63 | and <a href="http://jakarta.apache.org/oro/" target="_top">jakarta-ORO</a>,
|
---|
| 64 | See <a href="../install.html#librarydependencies">installation dependencies</a>
|
---|
| 65 | concerning the supporting libraries.</p>
|
---|
| 66 | <p>
|
---|
| 67 | The property <code>ant.regexp.regexpimpl</code> governs which regular expression implementation will be chosen.
|
---|
| 68 | Possible values for this property are :
|
---|
| 69 | <ul>
|
---|
| 70 | <li>
|
---|
| 71 | org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
|
---|
| 72 | </li>
|
---|
| 73 | <li>
|
---|
| 74 | org.apache.tools.ant.util.regexp.JakartaOroRegexp
|
---|
| 75 | </li>
|
---|
| 76 | <li>
|
---|
| 77 | org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
|
---|
| 78 | </li>
|
---|
| 79 | </ul>
|
---|
| 80 | It can also be another implementation of the interface <code>org.apache.tools.ant.util.regexp.Regexp</code>.
|
---|
| 81 | If <code>ant.regexp.regexpimpl</code> is not defined, ant checks in the order Jdk14Regexp, JakartaOroRegexp,
|
---|
| 82 | JakartaRegexp for the availability of the corresponding library. The first of these 3 which is found will be used.</p>
|
---|
| 83 | <p>
|
---|
| 84 | There are cross-platform issues for matches related to line terminator.
|
---|
| 85 | For example if you use $ to anchor your regular expression on the end of a line
|
---|
| 86 | the results might be very different depending on both your platform and the regular
|
---|
| 87 | expression library you use. It is 'highly recommended' that you test your pattern on
|
---|
| 88 | both Unix and Windows platforms before you rely on it.
|
---|
| 89 | <ul>
|
---|
| 90 | <li>Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.</li>
|
---|
| 91 | <li>Jakarta RegExp uses a system-dependant line terminator.</li>
|
---|
| 92 | <li>JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default
|
---|
| 93 | but is configured in the wrapper to use only '\n' (UNIX_LINE)</li>
|
---|
| 94 | </ul>
|
---|
| 95 | <em>We <b>strongly</b> recommend that you use Jakarta Oro.</em>
|
---|
| 96 | </p>
|
---|
| 97 | <h3>Usage</h3>
|
---|
| 98 | The following tasks and types use the Regexp type :
|
---|
| 99 | <ul>
|
---|
| 100 | <li><a href="../OptionalTasks/replaceregexp.html">ReplaceRegExp task</a></li>
|
---|
| 101 | <li><a href="filterchain.html#linecontainsregexp">LineContainsRegexp filter</a></li>
|
---|
| 102 | </ul>
|
---|
| 103 | <p>
|
---|
| 104 | These string filters also use the mechanism of regexp to choose a regular expression implementation :
|
---|
| 105 | </p>
|
---|
| 106 | <ul>
|
---|
| 107 | <li><a href="filterchain.html#containsregex">ContainsRegex string filter</a></li>
|
---|
| 108 | <li><a href="filterchain.html#replaceregex">ReplaceRegex string filter</a></li>
|
---|
| 109 | </ul>
|
---|
| 110 |
|
---|
| 111 | </body>
|
---|
| 112 | </html>
|
---|