You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

regexp.html 4.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>Regexp Type</title>
  20. </head>
  21. <body>
  22. <h2 id="regexp">Regexp</h2>
  23. <p>
  24. Regexp represents a regular expression.
  25. <h3>Parameters</h3>
  26. <table class="attr">
  27. <tr>
  28. <th scope="col">Attribute</th>
  29. <th scope="col">Description</th>
  30. <th scope="col">Required</th>
  31. </tr>
  32. <tr>
  33. <td>pattern</td>
  34. <td>regular expression pattern</td>
  35. <td>Yes</td>
  36. </tr>
  37. <tr>
  38. <td>refid</td>
  39. <td>Makes this <code>regexp</code>
  40. a <a href="../using.html#references">reference</a> to
  41. a <code>regexp</code> defined elsewhere. If specified no other
  42. attributes or nested elements are allowed.</td>
  43. <td>No</td>
  44. </tr>
  45. </table>
  46. <h3>Examples</h3>
  47. <pre>&lt;regexp id="myregexp" pattern="alpha(.+)beta"/&gt;</pre>
  48. <p>Defines a regular expression for later use with <var>id</var> <q>myregexp</q>.</p>
  49. <pre>&lt;regexp refid="myregexp"/&gt;</pre>
  50. <p>Use the regular expression with <var>id</var> <q>myregexp</q>.</p>
  51. <h3 id="implementation">Choice of regular expression implementation</h3>
  52. <p>Apache Ant comes with wrappers for
  53. the <a href="https://docs.oracle.com/javase/8/docs/api/java/util/regex/package-summary.html"
  54. target="_top"><code>java.util.regex</code>
  55. package</a>, <a href="https://attic.apache.org/projects/jakarta-regexp.html"
  56. target="_top">jakarta-regexp</a> and <a href="https://attic.apache.org/projects/jakarta-oro.html"
  57. target="_top">jakarta-ORO</a>, see <a href="../install.html#librarydependencies">installation
  58. dependencies</a> concerning the supporting libraries.</p>
  59. <p>The property <code>ant.regexp.regexpimpl</code> governs which regular expression implementation
  60. will be chosen. Possible values for this property are:</p>
  61. <ul>
  62. <li><code class="code">org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp</code></li>
  63. <li><code class="code">org.apache.tools.ant.util.regexp.JakartaOroRegexp</code></li>
  64. <li><code class="code">org.apache.tools.ant.util.regexp.JakartaRegexpRegexp</code></li>
  65. </ul>
  66. <p>It can also be another implementation of the
  67. interface <code class="code">org.apache.tools.ant.util.regexp.Regexp</code>.
  68. If <code>ant.regexp.regexpimpl</code> is not defined, Ant uses Jdk14Regexp as this is always
  69. available.</p>
  70. <p>
  71. There are cross-platform issues for matches related to line terminator. For example if you
  72. use <q>$</q> to anchor your regular expression on the end of a line the results might be very
  73. different depending on both your platform and the regular expression library you use. It
  74. is <em>highly recommended</em> that you test your pattern on both Unix and Windows platforms before
  75. you rely on it.</p>
  76. <ul>
  77. <li>Jakarta Oro defines a line terminator as <q>\n</q> and is consistent with Perl.</li>
  78. <li>Jakarta RegExp uses a system-dependent line terminator.</li>
  79. <li><code>java.util.regex</code> uses <q>\n</q>, <q>\r\n</q>, <q>\u0085</q>, <q>\u2028</q>, <q>\u2029</q> as a
  80. default but is configured in the wrapper to use only <q>\n</q> (UNIX_LINE)</li>
  81. </ul>
  82. <p><em>We used to recommend that you use Jakarta ORO but since its development has been retired
  83. Java's built-in regex package is likely the best choice going forward.</em></p>
  84. <h3>Usage</h3> The following tasks and types use the Regexp type:
  85. <ul>
  86. <li><a href="../Tasks/replaceregexp.html">ReplaceRegExp task</a></li>
  87. <li><a href="filterchain.html#linecontainsregexp">LineContainsRegexp filter</a></li>
  88. </ul>
  89. <p>These string filters also use the mechanism of regexp to choose a regular expression
  90. implementation:</p>
  91. <ul>
  92. <li><a href="filterchain.html#containsregex">ContainsRegex string filter</a></li>
  93. <li><a href="filterchain.html#replaceregex">ReplaceRegex string filter</a></li>
  94. <li><a href="selectors.html#filenameselect">filename selector</a></li>
  95. <li><a href="resources.html#rsel.name">name resource selector</a></li>
  96. <li><a href="selectors.html#regexpselect">containsregexp selector</a></li>
  97. </ul>
  98. </body>
  99. </html>