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.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  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>
  27. <tr>
  28. <td valign="top"><b>Attribute</b></td>
  29. <td valign="top"><b>Description</b></td>
  30. <td align="center" valign="top"><b>Required</b></td>
  31. </tr>
  32. <tr>
  33. <td valign="top">pattern</td>
  34. <td valign="top">regular expression pattern</td>
  35. <td valign="top" align="center">Yes</td>
  36. </tr>
  37. </table>
  38. <h3>Examples</h3>
  39. <pre>&lt;regexp id="myregexp" pattern="alpha(.+)beta"/&gt;</pre>
  40. <p>
  41. Defines a regular expression for later use with id myregexp.
  42. </p>
  43. <pre>&lt;regexp refid="myregexp"/&gt;</pre>
  44. <p>
  45. Use the regular expression with id myregexp.
  46. </p>
  47. <h3 id="implementation">Choice of regular expression implementation</h3>
  48. <p>
  49. Apache Ant comes with
  50. wrappers for
  51. <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/package-summary.html" target="_top">the java.util.regex package</a>,
  52. <a href="http://attic.apache.org/projects/jakarta-regexp.html" target="_top">jakarta-regexp</a>
  53. and <a href="http://attic.apache.org/projects/jakarta-oro.html" target="_top">jakarta-ORO</a>,
  54. See <a href="../install.html#librarydependencies">installation dependencies</a>
  55. concerning the supporting libraries.</p>
  56. <p>
  57. The property <code>ant.regexp.regexpimpl</code> governs which regular expression implementation will be chosen.
  58. Possible values for this property are:</p>
  59. <ul>
  60. <li>org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp</li>
  61. <li>org.apache.tools.ant.util.regexp.JakartaOroRegexp</li>
  62. <li>org.apache.tools.ant.util.regexp.JakartaRegexpRegexp</li>
  63. </ul>
  64. <p>It can also be another implementation of the interface <code>org.apache.tools.ant.util.regexp.Regexp</code>.
  65. If <code>ant.regexp.regexpimpl</code> is not defined, Ant uses Jdk14Regexp as this is always available.</p>
  66. <p>
  67. There are cross-platform issues for matches related to line terminator.
  68. For example if you use $ to anchor your regular expression on the end of a line
  69. the results might be very different depending on both your platform and the regular
  70. expression library you use. It is 'highly recommended' that you test your pattern on
  71. both Unix and Windows platforms before you rely on it.</p>
  72. <ul>
  73. <li>Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.</li>
  74. <li>Jakarta RegExp uses a system-dependent line terminator.</li>
  75. <li>JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default
  76. but is configured in the wrapper to use only '\n' (UNIX_LINE)</li>
  77. </ul>
  78. <p>
  79. <em>We used to recommend that you use Jakarta ORO but since its
  80. development has been retired Java's built-in regex package is likely
  81. the best choice going forward.</em>
  82. </p>
  83. <h3>Usage</h3>
  84. 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>
  90. These string filters also use the mechanism of regexp to choose a regular expression implementation :
  91. </p>
  92. <ul>
  93. <li><a href="filterchain.html#containsregex">ContainsRegex string filter</a></li>
  94. <li><a href="filterchain.html#replaceregex">ReplaceRegex string filter</a></li>
  95. <li><a href="selectors.html#filenameselect">filename selector</a></li>
  96. <li><a href="resources.html#rsel.name">name resource selector</a></li>
  97. <li><a href="selectors.html#regexpselect">containsregexp selector</a></li>
  98. </ul>
  99. </body>
  100. </html>