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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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><a name="regexp">Regexp</a></h2>
  23. <p>
  24. Regexp represents a regular expression.
  25. <h3>Parameters</h3>
  26. <table border="1" cellpadding="2" cellspacing="0">
  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. <blockquote><pre>
  40. &lt;regexp id="myregexp" pattern="alpha(.+)beta"/&gt;<br>
  41. </pre></blockquote>
  42. <p>
  43. Defines a regular expression for later use with id myregexp.
  44. </p>
  45. <blockquote><pre>
  46. &lt;regexp refid="myregexp"/&gt;<br>
  47. </pre></blockquote>
  48. <p>
  49. Use the regular expression with id myregexp.
  50. </p>
  51. <h3><a name="implementation">Choice of regular expression implementation</a></h3>
  52. <p>
  53. Apache Ant comes with
  54. wrappers for
  55. <a href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/package-summary.html" target="_top">the java.util.regex package</a>,
  56. <a href="http://attic.apache.org/projects/jakarta-regexp.html" target="_top">jakarta-regexp</a>
  57. and <a href="http://attic.apache.org/projects/jakarta-oro.html" target="_top">jakarta-ORO</a>,
  58. See <a href="../install.html#librarydependencies">installation dependencies</a>
  59. concerning the supporting libraries.</p>
  60. <p>
  61. The property <code>ant.regexp.regexpimpl</code> governs which regular expression implementation will be chosen.
  62. Possible values for this property are :
  63. <ul>
  64. <li>
  65. org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
  66. </li>
  67. <li>
  68. org.apache.tools.ant.util.regexp.JakartaOroRegexp
  69. </li>
  70. <li>
  71. org.apache.tools.ant.util.regexp.JakartaRegexpRegexp
  72. </li>
  73. </ul>
  74. It can also be another implementation of the interface <code>org.apache.tools.ant.util.regexp.Regexp</code>.
  75. If <code>ant.regexp.regexpimpl</code> is not defined, Ant uses Jdk14Regexp as this is always available.</p>
  76. <p>
  77. There are cross-platform issues for matches related to line terminator.
  78. For example if you use $ to anchor your regular expression on the end of a line
  79. the results might be very different depending on both your platform and the regular
  80. expression library you use. It is 'highly recommended' that you test your pattern on
  81. both Unix and Windows platforms before you rely on it.
  82. <ul>
  83. <li>Jakarta Oro defines a line terminator as '\n' and is consistent with Perl.</li>
  84. <li>Jakarta RegExp uses a system-dependent line terminator.</li>
  85. <li>JDK 1.4 uses '\n', '\r\n', '\u0085', '\u2028', '\u2029' as a default
  86. but is configured in the wrapper to use only '\n' (UNIX_LINE)</li>
  87. </ul>
  88. <em>We used to recommend that you use Jakarta ORO but since its
  89. development has been retired Java's built-in regex package is likely
  90. the best choice going forward.</em>
  91. </p>
  92. <h3>Usage</h3>
  93. The following tasks and types use the Regexp type :
  94. <ul>
  95. <li><a href="../Tasks/replaceregexp.html">ReplaceRegExp task</a></li>
  96. <li><a href="filterchain.html#linecontainsregexp">LineContainsRegexp filter</a></li>
  97. </ul>
  98. <p>
  99. These string filters also use the mechanism of regexp to choose a regular expression implementation :
  100. </p>
  101. <ul>
  102. <li><a href="filterchain.html#containsregex">ContainsRegex string filter</a></li>
  103. <li><a href="filterchain.html#replaceregex">ReplaceRegex string filter</a></li>
  104. <li><a href="selectors.html#filenameselect">filename selector</a></li>
  105. <li><a href="resources.html#rsel.name">name resource selector</a></li>
  106. <li><a href="selectors.html#regexpselect">containsregexp selector</a></li>
  107. </ul>
  108. </body>
  109. </html>