source: release-kits/lirk3/ant-scripts/tasks/antelope/docs/manual/bk03ch22.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 7.4 KB
Line 
1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Chapter 22. Grep Task</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1"><link rel="start" href="index.html" title="Antelope Users Guide"><link rel="up" href="bk03.html" title="Additional Ant Tasks"><link rel="prev" href="bk03ch21.html" title="Chapter 21. Call Task"><link rel="next" href="bk03ch23.html" title="Chapter 23. Split Task"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 22. Grep Task</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="bk03ch21.html">Prev</a> </td><th width="60%" align="center">Additional Ant Tasks</th><td width="20%" align="right"> <a accesskey="n" href="bk03ch23.html">Next</a></td></tr></table><hr></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="greptask"></a>Chapter 22. Grep Task</h2></div></div></div>
2<STYLE TYPE="text/css"> <!-- @import url(./style.css); --> </STYLE>
3 <p>
4This task uses a regular expression to do pattern matching against a string and store the match in a property. This is useful for extracting a substring, or checking that an html form contains a particular value.</p><p>
5To use this task in your build files, include a task definition like this:
6</p><pre class="programlisting">
7
8 &lt;taskdef name="grep" classname="ise.antelope.tasks.Find"/&gt;
9
10</pre><p>
11</p><p>
12</p><div class="table"><a name="id2524918"></a><p class="title"><b>Table 22.1. Grep Task Attributes</b></p><table summary="Grep Task Attributes" border="1"><colgroup><col><col><col><col></colgroup><thead><tr><th>Attribute</th><th>Description</th><th>Default</th><th>Required</th></tr></thead><tbody><tr><td>in</td><td>The string to perform the regular expression matching on</td><td>None</td><td>Yes</td></tr><tr><td>regex</td><td>The regular expression. See the Java API documentation for java.util.regex.Pattern for the details of the syntax for this expression.</td><td>None</td><td>Yes</td></tr><tr><td>group</td><td>The regular expression group to return in the property.</td><td>0</td><td>No</td></tr><tr><td>property</td><td>The name of a property in which to put the matched value.</td><td>None</td><td>Yes</td></tr><tr><td>allmatches</td><td>A regex may find multiple matches in the input string. If this attribute is set to true, then the property set after the grep will contain all matches. The individual matches can be separated by using the 'separator' attribute (see below). The default is 'false', that is, only return the first match.</td><td>false</td><td>No</td></tr><tr><td>separator</td><td>When 'allmatches' is set to true and there are multiple matches, this value will be used to separate the individual matches.</td><td>${line.separator}</td><td>No</td></tr><tr><td>caseinsensitive</td><td>Enables case-insensitive matching.</td><td>false</td><td>No</td></tr><tr><td>comments</td><td>Permits whitespace and comments in pattern.</td><td>false</td><td>No</td></tr><tr><td>dotall</td><td>Enables dotall mode.</td><td>false</td><td>No</td></tr><tr><td>multiline</td><td>Enables multiline mode.</td><td>false</td><td>No</td></tr><tr><td>unicodecase</td><td>Enables Unicode-aware case folding.</td><td>false</td><td>No</td></tr><tr><td>canoneq</td><td>Enables canonical equivalence.</td><td>false</td><td>No</td></tr><tr><td>unixlines</td><td>Enables Unix lines mode.</td><td>false</td><td>No</td></tr></tbody></table></div><p>
13</p><p>
14Examples:
15</p><p>
16</p><pre class="programlisting">
17
18 &lt;target name="test" description="Test grep"&gt;
19 &lt;grep in="${response}" regex="(account id=)([0-9]+)" group="2" property="AccountId"/&gt;
20 &lt;echo&gt;Account Id: ${AccountId} received for ${user}&lt;/echo&gt;
21 &lt;/target&gt;
22
23</pre><p>
24</p><p>
25This example uses the 'unset' and 'post' tasks along with 'grep' to list the download url's for Ant:
26</p><pre class="programlisting">
27
28
29 &lt;target name="test"&gt;
30 &lt;unset name="ant_download_page"/&gt;
31 &lt;post to="http://ant.apache.org/bindownload.cgi"
32 verbose="no"
33 property="ant_download_page"/&gt;
34 &lt;grep in="${ant_download_page}"
35 regex="select name=&amp;quot;Preferred.*?&amp;lt;/select"
36 dotall="yes"
37 property="options"/&gt;
38
39 &lt;unset name="urls"/&gt;
40 &lt;grep in="${options}"
41 regex="&amp;lt;option.*?&amp;gt;(.*?)&amp;lt;/option&amp;gt;"
42 group="1"
43 allmatches="yes"
44 separator="${line.separator}"
45 property="urls"/&gt;
46 &lt;echo&gt;${urls}&lt;/echo&gt;
47 &lt;/target&gt;
48
49 [echo] http://apache.gr-linux.com
50 [echo] http://www.reverse.net/pub/apache
51 [echo] http://government-grants.org/mirrors/apache.org
52 [echo] http://apache.mirrors.hoobly.com
53 [echo] http://apache.mirrormax.net
54 [echo] http://www.ibiblio.org/pub/mirrors/apache
55 [echo] http://www.mirrormonster.com/apache.org
56 [echo] http://apache.towardex.com
57 [echo] http://www.axint.net/apache
58 [echo] http://apache.tradebit.com/pub
59 [echo] http://www.eng.lsu.edu/mirrors/apache
60 [echo] http://mirrors.isc.org/pub/apache
61 [echo] http://www.theshell.com/pub/apache
62 [echo] http://apache.mirrors.redwire.net
63 [echo] http://apache.cs.utah.edu
64 [echo] http://www.tux.org/pub/net/apache/dist
65 [echo] http://linux.cs.lewisu.edu/apache
66 [echo] http://apache.roweboat.net
67 [echo] http://apache.secsup.org/dist
68 [echo] http://www.signal42.com/mirrors/apache
69 [echo] http://apache.mirror99.com
70 [echo] http://mirrors.xtria.com/apache
71 [echo] http://apache.downlod.in
72 [echo] http://apache.mirrors.pair.com
73 [echo] http://apache.seekmeup.com
74 [echo] http://mirrors.combose.com/apache
75 [echo] http://www.wmwweb.com/apache
76 [echo] http://apache.intissite.com
77 [echo] http://apache.oregonstate.edu
78 [echo] http://apache.bestwebcover.com
79 [echo] http://ftp.wayne.edu/apache
80 [echo] http://mirrors.ccs.neu.edu/Apache/dist
81 [echo] http://www.ip97.com/apache.org
82 [echo] http://apache.mirrors.versehost.com
83 [echo] http://mirrors.playboy.com/apache
84 [echo] ftp://ftp.ccs.neu.edu/net/mirrors/Apache/dist
85 [echo] ftp://apache.mirrors.pair.com
86 [echo] ftp://apache.cs.utah.edu/pub/apache.org
87 [echo] ftp://apache.mirrors.redwire.net/pub/apache
88 [echo] ftp://ftp.oregonstate.edu/pub/apache
89 [echo] ftp://ftp.wayne.edu/apache
90 [echo] ftp://mirror.sg.depaul.edu/pub/apache
91 [echo] ftp://www.ibiblio.org/pub/mirrors/apache
92 [echo] ftp://ftp.tux.org/pub/net/apache/dist
93 [echo] ftp://www.reverse.net/pub/apache
94 [echo] ftp://apache.secsup.org/pub/apache/dist
95 [echo] http://www.eu.apache.org/dist (backup)
96 [echo] http://www.apache.org/dist (backup)
97
98</pre><p>
99</p></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="bk03ch21.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="bk03.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="bk03ch23.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 21. Call Task </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 23. Split Task</td></tr></table></div></body></html>
Note: See TracBrowser for help on using the repository browser.