~ubuntu-branches/ubuntu/trusty/ant/trusty

« back to all changes in this revision

Viewing changes to docs/manual/OptionalTasks/replaceregexp.html

  • Committer: Bazaar Package Importer
  • Author(s): James Page, James Page, Niels Thykier
  • Date: 2011-05-04 15:16:42 UTC
  • mfrom: (5.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20110504151642-3cm7tbh8rwkdbpx8
[ James Page ]
* New upstream release (Closes: #613914).
  - Fix FTBFS for jug with ant 1.8.1 (Closes: #610320).
* Bumped Standards-Version to 3.9.2, no changes.
* Removed ant-nodeps.jar from install as now part of ant core. 
* Added myself to Uploaders.

[ Niels Thykier ]
* Added missing mh_clean, thanks to Miguel Landaeta for spotting
  this.
* Fixed a typo in the ant manpage.
* Made short descriptions unique.
* Bumped debhelper compat to 7.
* Removed empty linda-override dir from ant-doc.
* Removed redundant Priority fields in d/control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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>ReplaceRegExp Task</title>
23
 
</head>
24
 
<body>
25
 
 
26
 
<h2><a name="replaceregexp">ReplaceRegExp</a></h2>
27
 
<h3>Description</h3>
28
 
<p>ReplaceRegExp is a directory based task for replacing the
29
 
occurrence of a given regular expression with a substitution pattern
30
 
in a selected file or set of files.</p>
31
 
 
32
 
<p>The output file is only written if it differs from the existing
33
 
file.  This prevents spurious rebuilds based on unchanged files which
34
 
have been regenerated by this task.</p> 
35
 
 
36
 
<p>Similar to <a href="../CoreTypes/mapper.html#regexp-mapper">regexp
37
 
type mappers</a> this task needs a supporting regular expression
38
 
library and an implementation of
39
 
<code>org.apache.tools.ant.util.regexp.Regexp</code>.
40
 
See details in the documentation of the <a href="../CoreTypes/regexp.html#implementation">Regexp Type</a>. </p>
41
 
 
42
 
<h3>Parameters</h3>
43
 
<table border="1" cellpadding="2" cellspacing="0">
44
 
  <tr>
45
 
    <td valign="top"><b>Attribute</b></td>
46
 
    <td valign="top"><b>Description</b></td>
47
 
    <td align="center" valign="top"><b>Required</b></td>
48
 
  </tr>
49
 
  <tr>
50
 
    <td valign="top">file</td>
51
 
    <td valign="top">file for which the regular expression should be replaced.</td>
52
 
    <td align="center">Yes if no nested <code>&lt;fileset&gt;</code> is used</td>
53
 
  </tr>
54
 
  <tr>
55
 
    <td valign="top">match</td>
56
 
    <td valign="top">The regular expression pattern to match in the file(s)</td>
57
 
    <td align="center">Yes, if no nested <code>&lt;regexp&gt;</code> is used</td>
58
 
  </tr>
59
 
  <tr>
60
 
    <td valign="top">replace</td>
61
 
    <td valign="top">The substitution pattern to place in the file(s) in place
62
 
                     of the regular expression.</td>
63
 
    <td align="center">Yes, if no nested <code>&lt;substitution&gt;</code> is used</td>
64
 
  </tr>
65
 
  <tr>
66
 
    <td valign="top">flags</td>
67
 
    <td valign="top">The flags to use when matching the regular expression.  For more
68
 
                     information, consult the Perl5 syntax<br>
69
 
                     g : Global replacement.  Replace all occurrences found<br>
70
 
                     i : Case Insensitive.  Do not consider case in the match<br>
71
 
                     m : Multiline.  Treat the string as multiple lines of input, using "^" and "$" as the start or end of any line, respectively, rather than start or end of string.<br>
72
 
                     s : Singleline.  Treat the string as a single line of input, using "." to match any character, including a newline, which normally, it would not match.<br>
73
 
    </td>
74
 
    <td valign="top" align="center">No</td>
75
 
  </tr>
76
 
  <tr>
77
 
    <td valign="top">byline</td>
78
 
    <td valign="top">Process the file(s) one line at a time, executing the replacement
79
 
                     on one line at a time (<i>true/false</i>).  This is useful if you
80
 
                     want to only replace the first occurrence of a regular expression on
81
 
                     each line, which is not easy to do when processing the file as a whole.
82
 
                     Defaults to <i>false</i>.</td>
83
 
    <td valign="top" align="center">No</td>
84
 
  </tr>
85
 
  <tr>
86
 
    <td valign="top">encoding</td>
87
 
    <td valign="top">The encoding of the file. <em>since Ant 1.6</em></td>
88
 
    <td align="center">No - defaults to default JVM encoding</td>
89
 
  </tr>
90
 
  <tr>
91
 
    <td valign="top">preserveLastModified</td>
92
 
    <td valign="top">Keep the file timestamp(s) even if the file(s)
93
 
      is(are) modified.  <em>since Ant 1.8.0.</em></td>
94
 
    <td valign="top" align="center">No, defaults to false</td>
95
 
  </tr>
96
 
</table>
97
 
<h3>Examples</h3>
98
 
<pre>
99
 
&lt;replaceregexp file=&quot;${src}/build.properties&quot;
100
 
               match=&quot;OldProperty=(.*)&quot;
101
 
               replace=&quot;NewProperty=\1&quot;
102
 
               byline=&quot;true&quot;
103
 
/&gt;
104
 
</pre>
105
 
<p>replaces occurrences of the property name &quot;OldProperty&quot;
106
 
 with &quot;NewProperty&quot; in a properties file, preserving the existing
107
 
value, in the file <code>${src}/build.properties</code></p>
108
 
 
109
 
<h3>Parameters specified as nested elements</h3>
110
 
<p>This task supports a nested <a href="../CoreTypes/fileset.html">FileSet</a>
111
 
   element.</p>
112
 
<p>Since Ant 1.8.0 this task supports any filesystem
113
 
  based <a href="../CoreTypes/resources.html#collection">resource
114
 
    collections</a> as nested elements.</p>
115
 
<p>This task supports a nested <i><a href="../CoreTypes/regexp.html">Regexp</a></i> element to specify
116
 
   the regular expression.  You can use this element to refer to a previously
117
 
   defined regular expression datatype instance.</p>
118
 
<blockquote>
119
 
     &lt;regexp id="id" pattern="alpha(.+)beta"/&gt;<br>
120
 
     &lt;regexp refid="id"/&gt;
121
 
</blockquote>
122
 
<p>This task supports a nested <i>Substitution</i> element to specify
123
 
   the substitution pattern.  You can use this element to refer to a previously
124
 
   defined substitution pattern datatype instance.</p>
125
 
<blockquote>
126
 
     &lt;substitution id="id" expression="beta\1alpha"/&gt;<br>
127
 
     &lt;substitution refid="id"/&gt;
128
 
</blockquote>
129
 
<h3>Examples</h3>
130
 
<blockquote>
131
 
  <pre>
132
 
&lt;replaceregexp byline=&quot;true&quot;&gt;
133
 
  &lt;regexp pattern=&quot;OldProperty=(.*)&quot;/&gt;
134
 
  &lt;substitution expression=&quot;NewProperty=\1&quot;/&gt;
135
 
  &lt;fileset dir=&quot;.&quot;&gt;
136
 
    &lt;include name=&quot;*.properties&quot;/&gt;
137
 
  &lt;/fileset&gt;
138
 
&lt;/replaceregexp&gt;
139
 
</pre></blockquote>
140
 
<p>replaces occurrences of the property name &quot;OldProperty&quot;
141
 
 with &quot;NewProperty&quot; in a properties file, preserving the existing
142
 
value, in all files ending in <code>.properties</code> in the current directory</p>
143
 
 
144
 
<blockquote>
145
 
<pre>&lt;replaceregexp match="\s+" replace=" " flags="g" byline="true"&gt;
146
 
    &lt;fileset dir="${html.dir}" includes="**/*.html"/&gt;
147
 
&lt;/replaceregexp&gt;
148
 
</pre></blockquote>
149
 
<p>replaces all whitespaces (blanks, tabs, etc) by one blank remaining the
150
 
line separator. So with input
151
 
 
152
 
<blockquote>
153
 
<pre>
154
 
&lt;html&gt;    &lt;body&gt;
155
 
&lt;&lt;TAB&gt;&gt;&lt;h1&gt;    T E S T   &lt;/h1&gt;  &lt;&lt;TAB&gt;&gt;    
156
 
&lt;&lt;TAB&gt;&gt; &lt;/body&gt;&lt;/html&gt;
157
 
</pre></blockquote>
158
 
would converted to
159
 
<pre>
160
 
&lt;html&gt; &lt;body&gt;
161
 
 &lt;h1&gt; T E S T &lt;/h1&gt; &lt;/body&gt;&lt;/html&gt;
162
 
</pre>
163
 
</p>
164
 
 
165
 
 
166
 
</body>
167
 
</html>
168