You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by George Bills <gb...@funnelback.com> on 2006/11/27 05:47:57 UTC

containsregex and concat

I've been trying to use a regular expression and the concat task to pull 
summary tables (<table class="summary">...</table>) out of a set of test 
reports. The reports are all HTML files sitting in ${report.path}. The 
task works fine up until I start trying to select output from it with 
<containsregex>. Is there something wrong with my regular expression? Is 
there an easier way to do this? Any help would be appreciated.

The code is:
====================
<target name="summary"> <!-- make a report summary -->
    <property name="summary.start" value="&lt;table 
class=&quot;summary&quot;&gt;" />
    <property name="summary.body"  value=".*?" /> <!-- enable "s" for 
newline matches -->
    <property name="summary.end"   value="&lt;/table&gt;" />
    <property name="summary.regex" 
value="${summary.start}${summary.body}${summary.end}" />
    <echo>${summary.regex}</echo>
    <concat>
        <header>HEADER</header>
        <fileset dir="${report.path}"
            includes="*.html"
            excludes="${summary.file}" />
            <filterchain>
                <tokenfilter>
                    <filetokenizer />
                    <containsregex flags="is"
                                   pattern="${summary.regex}" />
                </tokenfilter>
            </filterchain>
        <footer>FOOTER</footer>
    </concat>
</target>
====================

The regular expression echoes as:
====================
<table class="summary">.*?</table>
====================

I've done some testing of the expression at 
http://www.fileformat.info/tool/regex.htm, and it seems to work there.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: containsregex and concat

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Ooops,
sorry i anwered the wrong mail ;-)

my mail below was meant as followup for =

http://marc.theaimsgroup.com/?l=ant-user&m=116464147926867&w=2

subject = [help] Search a string in a file

Sorry, Gilbert

-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de] 
Sent: Tuesday, November 28, 2006 7:30 AM
To: Ant Users List
Subject: RE: containsregex and concat


Hi,

i'm still a newbie to ruby, maybe there's a more
elegant solution, you need jruby available for ant

http://dist.codehaus.org/jruby/jruby-bin-0.9.1.tar.gz


given test.txt =

abcd
xyz
what
why
Rebuild All: 1 failed, 0 skipped
new world
Rebuild All: 0 failed, 0 skipped
techno
Rebuild All: 1 failed, 0 skipped
Rebuild All: 10 failed, 0 Skipped


quick hack =

<target name="depends">
        <script language="ruby">
        <![CDATA[
            counterfailed=0;
            counterskipped=0;
            File.open("Y:/test.txt", "r").each do |line|
                if line =~ /(\d{1,2}).+(\d{1,2})/
                    counterfailed += $1.to_i
                    counterskipped += $2.to_i
                end
            end
            puts 'Summary :' 
            puts 'Failed == ' +counterfailed.to_s
            puts 'Skipped == ' +counterskipped.to_s
            
            $project.setNewProperty "failed", counterfailed.to_s
            $project.setNewProperty "skipped", counterskipped.to_s
            

          ]]>
          </script>
	</target>
 
	<target name="main" depends="depends">     
     <echo>$${failed} == ${failed}</echo>   
     <echo>$${skipped} == ${skipped}</echo>   
	</target>

depends:
   [script] Summary :
   [script] Failed == 12
   [script] Skipped == 0
main:
     [echo] ${failed} == 12
     [echo] ${skipped} == 0
BUILD SUCCESSFUL
Total time: 1 second

The regular expression \d{1,2} matches one or max 2 occurences of a
digit,
hope you don't get such a lot of failed rebuilds ;-)

If needed you can match 1 or 2 or 3 digits with \d{1,3} and so on ...

 
Regards, Gilbert

-----Original Message-----
From: George Bills [mailto:gbills@funnelback.com] 
Sent: Tuesday, November 28, 2006 6:14 AM
To: Ant Users List
Subject: Re: containsregex and concat

Thanks: the regular expression works now, which is progress. 
Unfortunately I'm getting all of the concatenated text, not just the 
matching text. If I use replace:
<filterchain>
  <!--<tokenfilter><filetokenizer />-->
    <containsregex flags="isg"
      pattern="${summary.regex}"
      replace="SUMMARYTABLE"
      byline="false" <!-- implies filetokenizer -->
      />
    <!-- </tokenfilter>-->
</filterchain>

I end up getting something like:
[concat] <html>
[concat] <head>
[concat] <title>summary</title>
[concat] <link rel="stylesheet" href="summary.css" type="text/css">
[concat] </head>
[concat] <body>
[concat] <a name="overview"></a>
[concat] <center>
[concat] SUMMARYTABLE
[concat] </center>
[concat] ...more HTML here...
[concat] </html>

I'm assuming it's because the file is just one big token - but if I use 
a line tokenizer, will I be able to match regular expressions over 
multiple lines?

Thanks for the help.

Rebhan, Gilbert wrote:
> Hi,
>
> <table[^>/]*>(.*?)</table>
>
> should match :
>
> <table class="summary">foobar</table>
>
> also with more than one attribute
>
> <table class="summary" foo="bar">foobar</table>
>
>
> foobar is  /1  (group 1)
>
>
> Regards, Gilbert
>  
>
> -----Original Message-----
> From: George Bills [mailto:gbills@funnelback.com] 
> Sent: Monday, November 27, 2006 6:41 AM
> To: Ant Users List
> Subject: Re: containsregex and concat
>
> Hrm, it probably isn't since advanced regexs are still black magic to 
> me. The "." was supposed to match any character, including a newline 
> (with the s flag), the * to say match 0-n of them and the ? to say be 
> lazy, match as little as possible (so that I don't pull in 
> <table>...</table><table>...</table> in one match).
>
> I just tried [^<], but it doesn't seem to work - I think because of
such
>
> things as "<table><tr>...</tr></table>" - the opening bracket of <tr> 
> conflicts. I tried [.&lt;&gt]*? to make sure that the "regex.body"
part 
> was matching the brackets, but that didn't work either.
>
> Also, <table class="summary"> was wrong - <table class="summary"(.*?)>

> is a little better since the tables can have more than the class 
> attribute (in fact, all of them do). But after changing that I'm 
> matching the entire document - <html> through to </html>. That might 
> just be because I'm using filetokenizer - if I make one match within 
> filetokenizer, do I end up getting the entire document? If so, how do
I 
> get only the matching text?
>
> Regex is now: <table class="summary".*?>.*?</table>
>
> Thanks for the help, I appreciate it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: containsregex and concat

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Hi,

i'm still a newbie to ruby, maybe there's a more
elegant solution, you need jruby available for ant

http://dist.codehaus.org/jruby/jruby-bin-0.9.1.tar.gz


given test.txt =

abcd
xyz
what
why
Rebuild All: 1 failed, 0 skipped
new world
Rebuild All: 0 failed, 0 skipped
techno
Rebuild All: 1 failed, 0 skipped
Rebuild All: 10 failed, 0 Skipped


quick hack =

<target name="depends">
        <script language="ruby">
        <![CDATA[
            counterfailed=0;
            counterskipped=0;
            File.open("Y:/test.txt", "r").each do |line|
                if line =~ /(\d{1,2}).+(\d{1,2})/
                    counterfailed += $1.to_i
                    counterskipped += $2.to_i
                end
            end
            puts 'Summary :' 
            puts 'Failed == ' +counterfailed.to_s
            puts 'Skipped == ' +counterskipped.to_s
            
            $project.setNewProperty "failed", counterfailed.to_s
            $project.setNewProperty "skipped", counterskipped.to_s
            

          ]]>
          </script>
	</target>
 
	<target name="main" depends="depends">     
     <echo>$${failed} == ${failed}</echo>   
     <echo>$${skipped} == ${skipped}</echo>   
	</target>

depends:
   [script] Summary :
   [script] Failed == 12
   [script] Skipped == 0
main:
     [echo] ${failed} == 12
     [echo] ${skipped} == 0
BUILD SUCCESSFUL
Total time: 1 second

The regular expression \d{1,2} matches one or max 2 occurences of a
digit,
hope you don't get such a lot of failed rebuilds ;-)

If needed you can match 1 or 2 or 3 digits with \d{1,3} and so on ...

 
Regards, Gilbert

-----Original Message-----
From: George Bills [mailto:gbills@funnelback.com] 
Sent: Tuesday, November 28, 2006 6:14 AM
To: Ant Users List
Subject: Re: containsregex and concat

Thanks: the regular expression works now, which is progress. 
Unfortunately I'm getting all of the concatenated text, not just the 
matching text. If I use replace:
<filterchain>
  <!--<tokenfilter><filetokenizer />-->
    <containsregex flags="isg"
      pattern="${summary.regex}"
      replace="SUMMARYTABLE"
      byline="false" <!-- implies filetokenizer -->
      />
    <!-- </tokenfilter>-->
</filterchain>

I end up getting something like:
[concat] <html>
[concat] <head>
[concat] <title>summary</title>
[concat] <link rel="stylesheet" href="summary.css" type="text/css">
[concat] </head>
[concat] <body>
[concat] <a name="overview"></a>
[concat] <center>
[concat] SUMMARYTABLE
[concat] </center>
[concat] ...more HTML here...
[concat] </html>

I'm assuming it's because the file is just one big token - but if I use 
a line tokenizer, will I be able to match regular expressions over 
multiple lines?

Thanks for the help.

Rebhan, Gilbert wrote:
> Hi,
>
> <table[^>/]*>(.*?)</table>
>
> should match :
>
> <table class="summary">foobar</table>
>
> also with more than one attribute
>
> <table class="summary" foo="bar">foobar</table>
>
>
> foobar is  /1  (group 1)
>
>
> Regards, Gilbert
>  
>
> -----Original Message-----
> From: George Bills [mailto:gbills@funnelback.com] 
> Sent: Monday, November 27, 2006 6:41 AM
> To: Ant Users List
> Subject: Re: containsregex and concat
>
> Hrm, it probably isn't since advanced regexs are still black magic to 
> me. The "." was supposed to match any character, including a newline 
> (with the s flag), the * to say match 0-n of them and the ? to say be 
> lazy, match as little as possible (so that I don't pull in 
> <table>...</table><table>...</table> in one match).
>
> I just tried [^<], but it doesn't seem to work - I think because of
such
>
> things as "<table><tr>...</tr></table>" - the opening bracket of <tr> 
> conflicts. I tried [.&lt;&gt]*? to make sure that the "regex.body"
part 
> was matching the brackets, but that didn't work either.
>
> Also, <table class="summary"> was wrong - <table class="summary"(.*?)>

> is a little better since the tables can have more than the class 
> attribute (in fact, all of them do). But after changing that I'm 
> matching the entire document - <html> through to </html>. That might 
> just be because I'm using filetokenizer - if I make one match within 
> filetokenizer, do I end up getting the entire document? If so, how do
I 
> get only the matching text?
>
> Regex is now: <table class="summary".*?>.*?</table>
>
> Thanks for the help, I appreciate it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: containsregex and concat

Posted by Brian Agnew <br...@oopsconsultancy.com>.
If your input file is XHTML, or can be transformed into XHTML (I'm sorry -
not been following the thread), then you can use XMLTask and specify the
XPath to the element you wish to change/insert at.

http://www.oopsconsultancy.com/software/xmltask

Brian

On Wed, November 29, 2006 05:07, George Bills wrote:
> Thanks Gilbert - except that doesn't work when tables span more than one
> line. "byline true" splits the text into multiple tokens, and the regex
> is applied independently to each token. So if the start of the
> expression (<table>) is on line one, the middle of the expression
> (<tr>blah</tr>...etc) is on line two, and the end of the expression
> (</table>) is on line three, then no one individual line / token
> matches, so nothing comes out (correct me if I'm wrong, but that's what
> seemed to happen in my testing). If byline is false, the entire text is
> one big token - so if I match the token, I get the entire token (the
> original input) back. Also, I wanted the entire table, not just the
> contents. I tried using "replace="\0"", but that just means that within
> the token I'm replacing the matching text with the matching text - not
> very useful.
>
> What I really wanted was a way of saying "give me the matching text and
> only the matching text, not the token that matches". I sort of solved it
> by writing a regular expression to match the entirety of input:
> "(.*?)(<table[^/<]*class="summary"[^/>]>(.*?)</table>)" . With the Ant
> encoding that ends up as:
> "(.*?)(&lt;table[^&lt;/]*class=&quot;summary&quot;[^&lt;/]*&gt;(.*?)&lt;/table&gt;)(.*)".
> I don't know that each table will only take one line of input (in fact,
> they won't), but since I know that there's only one table in each input
> file, I can match the entire file and use "replace="\2"" to replace the
> entire match (all input) with the second matching group (the table).
>
> So, that works for one file. The problem I have now is getting it to
> work for multiple files - each file that I concatenate has exactly one
> summary table that I want to extract and place in a single HTML summary
> file. I tried:
> (A) Concatenating (<concat>) all of the files and applying a filterchain
> - but the filterchain filters all the input once, not once per file. So
> I concatenate the files first, then apply the regex - which means I only
> get the one matching table from the entire concatenation, not one
> matching table from each file that I concatenate.
> (B) Copying (<copy>) all of the files to a single file - in this case,
> the filterchain extracts the individual tables from each file - but I
> only end up with one file, because I can't make it concatenate them all
> to one destination (even with a mergemapper). "enablemultiplemappings"
> doesn't seem to help.
>
> If there was some way of saying "for each file, apply the transform
> *before* concatenating, not after", then that would work, but as far as
> I can see, there isn't. Any ideas?
>
> Rebhan, Gilbert wrote:
>> Hi,
>>
>> <target name="depends">
>>      <echo file="Y:/test.html">
>>          <![CDATA[
>>          <html>
>>          <head>
>>          <title>summary</title>
>>          <link rel="stylesheet" href="summary.css" type="text/css">
>>          </head>
>>          <body>
>>          <a name="overview"></a>
>>          <center>
>>          <table class="summary"> was wrong </table>
>>          </center>
>>          </html>
>>          ]]>
>>          </echo>
>> 	</target>
>>
>> 	<target name="main" depends="depends">
>>
>> 	<loadfile srcfile="Y:/test.html" property="summary">
>>         <filterchain>
>>             <containsregex
>>               pattern='&lt;table[^&lt;/]*&gt;(.*?)&lt;/table&gt;'
>>               replace="\1"
>>               byline="true"
>>               />
>>             <tokenfilter>
>>                 <!-- to get rid of whitespace in ${summary} -->
>>                 <trim/>
>>             </tokenfilter>
>>         </filterchain>
>>     </loadfile>
>>
>>      <echo>Summary == ${summary}</echo>
>>
>> 	</target>
>>
>> gives only the text =
>>
>> depends:
>> main:
>>      [echo] Summary == was wrong
>> BUILD SUCCESSFUL
>> Total time: 407 milliseconds
>>
>>
>> you have to use \1 and byline=true
>>
>> Regards, Gilbert
>>
>> -----Original Message-----
>> From: George Bills [mailto:gbills@funnelback.com]
>> Sent: Tuesday, November 28, 2006 6:14 AM
>> To: Ant Users List
>> Subject: Re: containsregex and concat
>>
>> Thanks: the regular expression works now, which is progress.
>> Unfortunately I'm getting all of the concatenated text, not just the
>> matching text. If I use replace:
>> <filterchain>
>>   <!--<tokenfilter><filetokenizer />-->
>>     <containsregex flags="isg"
>>       pattern="${summary.regex}"
>>       replace="SUMMARYTABLE"
>>       byline="false" <!-- implies filetokenizer -->
>>       />
>>     <!-- </tokenfilter>-->
>> </filterchain>
>>
>> I end up getting something like:
>> [concat] <html>
>> [concat] <head>
>> [concat] <title>summary</title>
>> [concat] <link rel="stylesheet" href="summary.css" type="text/css">
>> [concat] </head>
>> [concat] <body>
>> [concat] <a name="overview"></a>
>> [concat] <center>
>> [concat] SUMMARYTABLE
>> [concat] </center>
>> [concat] ...more HTML here...
>> [concat] </html>
>>
>> I'm assuming it's because the file is just one big token - but if I use
>> a line tokenizer, will I be able to match regular expressions over
>> multiple lines?
>>
>> Thanks for the help.
>>
>> Rebhan, Gilbert wrote:
>>
>>> Hi,
>>>
>>> <table[^>/]*>(.*?)</table>
>>>
>>> should match :
>>>
>>> <table class="summary">foobar</table>
>>>
>>> also with more than one attribute
>>>
>>> <table class="summary" foo="bar">foobar</table>
>>>
>>>
>>> foobar is  /1  (group 1)
>>>
>>>
>>> Regards, Gilbert
>>>
>>>
>>> -----Original Message-----
>>> From: George Bills [mailto:gbills@funnelback.com]
>>> Sent: Monday, November 27, 2006 6:41 AM
>>> To: Ant Users List
>>> Subject: Re: containsregex and concat
>>>
>>> Hrm, it probably isn't since advanced regexs are still black magic to
>>> me. The "." was supposed to match any character, including a newline
>>> (with the s flag), the * to say match 0-n of them and the ? to say be
>>> lazy, match as little as possible (so that I don't pull in
>>> <table>...</table><table>...</table> in one match).
>>>
>>> I just tried [^<], but it doesn't seem to work - I think because of
>>>
>> such
>>
>>> things as "<table><tr>...</tr></table>" - the opening bracket of <tr>
>>> conflicts. I tried [.&lt;&gt]*? to make sure that the "regex.body"
>>>
>> part
>>
>>> was matching the brackets, but that didn't work either.
>>>
>>> Also, <table class="summary"> was wrong - <table class="summary"(.*?)>
>>>
>>
>>
>>> is a little better since the tables can have more than the class
>>> attribute (in fact, all of them do). But after changing that I'm
>>> matching the entire document - <html> through to </html>. That might
>>> just be because I'm using filetokenizer - if I make one match within
>>> filetokenizer, do I end up getting the entire document? If so, how do
>>>
>> I
>>
>>> get only the matching text?
>>>
>>> Regex is now: <table class="summary".*?>.*?</table>
>>>
>>> Thanks for the help, I appreciate it.
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>>> For additional commands, e-mail: user-help@ant.apache.org
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


-- 
Brian Agnew                  http://www.oopsconsultancy.com
OOPS Consultancy Ltd
Tel: +44 (0)7720 397526
Fax: +44 (0)20 8682 0012


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: containsregex and concat

Posted by George Bills <gb...@funnelback.com>.
Thanks Gilbert - except that doesn't work when tables span more than one 
line. "byline true" splits the text into multiple tokens, and the regex 
is applied independently to each token. So if the start of the 
expression (<table>) is on line one, the middle of the expression 
(<tr>blah</tr>...etc) is on line two, and the end of the expression 
(</table>) is on line three, then no one individual line / token 
matches, so nothing comes out (correct me if I'm wrong, but that's what 
seemed to happen in my testing). If byline is false, the entire text is 
one big token - so if I match the token, I get the entire token (the 
original input) back. Also, I wanted the entire table, not just the 
contents. I tried using "replace="\0"", but that just means that within 
the token I'm replacing the matching text with the matching text - not 
very useful.

What I really wanted was a way of saying "give me the matching text and 
only the matching text, not the token that matches". I sort of solved it 
by writing a regular expression to match the entirety of input: 
"(.*?)(<table[^/<]*class="summary"[^/>]>(.*?)</table>)" . With the Ant 
encoding that ends up as: 
"(.*?)(&lt;table[^&lt;/]*class=&quot;summary&quot;[^&lt;/]*&gt;(.*?)&lt;/table&gt;)(.*)". 
I don't know that each table will only take one line of input (in fact, 
they won't), but since I know that there's only one table in each input 
file, I can match the entire file and use "replace="\2"" to replace the 
entire match (all input) with the second matching group (the table).

So, that works for one file. The problem I have now is getting it to 
work for multiple files - each file that I concatenate has exactly one 
summary table that I want to extract and place in a single HTML summary 
file. I tried:
(A) Concatenating (<concat>) all of the files and applying a filterchain 
- but the filterchain filters all the input once, not once per file. So 
I concatenate the files first, then apply the regex - which means I only 
get the one matching table from the entire concatenation, not one 
matching table from each file that I concatenate.
(B) Copying (<copy>) all of the files to a single file - in this case, 
the filterchain extracts the individual tables from each file - but I 
only end up with one file, because I can't make it concatenate them all 
to one destination (even with a mergemapper). "enablemultiplemappings" 
doesn't seem to help.

If there was some way of saying "for each file, apply the transform 
*before* concatenating, not after", then that would work, but as far as 
I can see, there isn't. Any ideas?

Rebhan, Gilbert wrote:
> Hi,
>
> <target name="depends">
>      <echo file="Y:/test.html">
>          <![CDATA[
>          <html>
>          <head>
>          <title>summary</title>
>          <link rel="stylesheet" href="summary.css" type="text/css">
>          </head>
>          <body>
>          <a name="overview"></a>
>          <center>
>          <table class="summary"> was wrong </table>
>          </center>
>          </html>
>          ]]>
>          </echo>
> 	</target>
>
> 	<target name="main" depends="depends">
>      
> 	<loadfile srcfile="Y:/test.html" property="summary">
>         <filterchain>
>             <containsregex
>               pattern='&lt;table[^&lt;/]*&gt;(.*?)&lt;/table&gt;'
>               replace="\1"
>               byline="true"
>               />
>             <tokenfilter>
>                 <!-- to get rid of whitespace in ${summary} -->
>                 <trim/>
>             </tokenfilter>
>         </filterchain>
>     </loadfile> 
>      
>      <echo>Summary == ${summary}</echo>
>         
> 	</target>
>
> gives only the text =
>
> depends:
> main:
>      [echo] Summary == was wrong
> BUILD SUCCESSFUL
> Total time: 407 milliseconds
>
>
> you have to use \1 and byline=true
>
> Regards, Gilbert 
>
> -----Original Message-----
> From: George Bills [mailto:gbills@funnelback.com] 
> Sent: Tuesday, November 28, 2006 6:14 AM
> To: Ant Users List
> Subject: Re: containsregex and concat
>
> Thanks: the regular expression works now, which is progress. 
> Unfortunately I'm getting all of the concatenated text, not just the 
> matching text. If I use replace:
> <filterchain>
>   <!--<tokenfilter><filetokenizer />-->
>     <containsregex flags="isg"
>       pattern="${summary.regex}"
>       replace="SUMMARYTABLE"
>       byline="false" <!-- implies filetokenizer -->
>       />
>     <!-- </tokenfilter>-->
> </filterchain>
>
> I end up getting something like:
> [concat] <html>
> [concat] <head>
> [concat] <title>summary</title>
> [concat] <link rel="stylesheet" href="summary.css" type="text/css">
> [concat] </head>
> [concat] <body>
> [concat] <a name="overview"></a>
> [concat] <center>
> [concat] SUMMARYTABLE
> [concat] </center>
> [concat] ...more HTML here...
> [concat] </html>
>
> I'm assuming it's because the file is just one big token - but if I use 
> a line tokenizer, will I be able to match regular expressions over 
> multiple lines?
>
> Thanks for the help.
>
> Rebhan, Gilbert wrote:
>   
>> Hi,
>>
>> <table[^>/]*>(.*?)</table>
>>
>> should match :
>>
>> <table class="summary">foobar</table>
>>
>> also with more than one attribute
>>
>> <table class="summary" foo="bar">foobar</table>
>>
>>
>> foobar is  /1  (group 1)
>>
>>
>> Regards, Gilbert
>>  
>>
>> -----Original Message-----
>> From: George Bills [mailto:gbills@funnelback.com] 
>> Sent: Monday, November 27, 2006 6:41 AM
>> To: Ant Users List
>> Subject: Re: containsregex and concat
>>
>> Hrm, it probably isn't since advanced regexs are still black magic to 
>> me. The "." was supposed to match any character, including a newline 
>> (with the s flag), the * to say match 0-n of them and the ? to say be 
>> lazy, match as little as possible (so that I don't pull in 
>> <table>...</table><table>...</table> in one match).
>>
>> I just tried [^<], but it doesn't seem to work - I think because of
>>     
> such
>   
>> things as "<table><tr>...</tr></table>" - the opening bracket of <tr> 
>> conflicts. I tried [.&lt;&gt]*? to make sure that the "regex.body"
>>     
> part 
>   
>> was matching the brackets, but that didn't work either.
>>
>> Also, <table class="summary"> was wrong - <table class="summary"(.*?)>
>>     
>
>   
>> is a little better since the tables can have more than the class 
>> attribute (in fact, all of them do). But after changing that I'm 
>> matching the entire document - <html> through to </html>. That might 
>> just be because I'm using filetokenizer - if I make one match within 
>> filetokenizer, do I end up getting the entire document? If so, how do
>>     
> I 
>   
>> get only the matching text?
>>
>> Regex is now: <table class="summary".*?>.*?</table>
>>
>> Thanks for the help, I appreciate it.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>>   
>>     
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: containsregex and concat

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Hi,

<target name="depends">
     <echo file="Y:/test.html">
         <![CDATA[
         <html>
         <head>
         <title>summary</title>
         <link rel="stylesheet" href="summary.css" type="text/css">
         </head>
         <body>
         <a name="overview"></a>
         <center>
         <table class="summary"> was wrong </table>
         </center>
         </html>
         ]]>
         </echo>
	</target>

	<target name="main" depends="depends">
     
	<loadfile srcfile="Y:/test.html" property="summary">
        <filterchain>
            <containsregex
              pattern='&lt;table[^&lt;/]*&gt;(.*?)&lt;/table&gt;'
              replace="\1"
              byline="true"
              />
            <tokenfilter>
                <!-- to get rid of whitespace in ${summary} -->
                <trim/>
            </tokenfilter>
        </filterchain>
    </loadfile> 
     
     <echo>Summary == ${summary}</echo>
        
	</target>

gives only the text =

depends:
main:
     [echo] Summary == was wrong
BUILD SUCCESSFUL
Total time: 407 milliseconds


you have to use \1 and byline=true

Regards, Gilbert 

-----Original Message-----
From: George Bills [mailto:gbills@funnelback.com] 
Sent: Tuesday, November 28, 2006 6:14 AM
To: Ant Users List
Subject: Re: containsregex and concat

Thanks: the regular expression works now, which is progress. 
Unfortunately I'm getting all of the concatenated text, not just the 
matching text. If I use replace:
<filterchain>
  <!--<tokenfilter><filetokenizer />-->
    <containsregex flags="isg"
      pattern="${summary.regex}"
      replace="SUMMARYTABLE"
      byline="false" <!-- implies filetokenizer -->
      />
    <!-- </tokenfilter>-->
</filterchain>

I end up getting something like:
[concat] <html>
[concat] <head>
[concat] <title>summary</title>
[concat] <link rel="stylesheet" href="summary.css" type="text/css">
[concat] </head>
[concat] <body>
[concat] <a name="overview"></a>
[concat] <center>
[concat] SUMMARYTABLE
[concat] </center>
[concat] ...more HTML here...
[concat] </html>

I'm assuming it's because the file is just one big token - but if I use 
a line tokenizer, will I be able to match regular expressions over 
multiple lines?

Thanks for the help.

Rebhan, Gilbert wrote:
> Hi,
>
> <table[^>/]*>(.*?)</table>
>
> should match :
>
> <table class="summary">foobar</table>
>
> also with more than one attribute
>
> <table class="summary" foo="bar">foobar</table>
>
>
> foobar is  /1  (group 1)
>
>
> Regards, Gilbert
>  
>
> -----Original Message-----
> From: George Bills [mailto:gbills@funnelback.com] 
> Sent: Monday, November 27, 2006 6:41 AM
> To: Ant Users List
> Subject: Re: containsregex and concat
>
> Hrm, it probably isn't since advanced regexs are still black magic to 
> me. The "." was supposed to match any character, including a newline 
> (with the s flag), the * to say match 0-n of them and the ? to say be 
> lazy, match as little as possible (so that I don't pull in 
> <table>...</table><table>...</table> in one match).
>
> I just tried [^<], but it doesn't seem to work - I think because of
such
>
> things as "<table><tr>...</tr></table>" - the opening bracket of <tr> 
> conflicts. I tried [.&lt;&gt]*? to make sure that the "regex.body"
part 
> was matching the brackets, but that didn't work either.
>
> Also, <table class="summary"> was wrong - <table class="summary"(.*?)>

> is a little better since the tables can have more than the class 
> attribute (in fact, all of them do). But after changing that I'm 
> matching the entire document - <html> through to </html>. That might 
> just be because I'm using filetokenizer - if I make one match within 
> filetokenizer, do I end up getting the entire document? If so, how do
I 
> get only the matching text?
>
> Regex is now: <table class="summary".*?>.*?</table>
>
> Thanks for the help, I appreciate it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: containsregex and concat

Posted by George Bills <gb...@funnelback.com>.
Thanks: the regular expression works now, which is progress. 
Unfortunately I'm getting all of the concatenated text, not just the 
matching text. If I use replace:
<filterchain>
  <!--<tokenfilter><filetokenizer />-->
    <containsregex flags="isg"
      pattern="${summary.regex}"
      replace="SUMMARYTABLE"
      byline="false" <!-- implies filetokenizer -->
      />
    <!-- </tokenfilter>-->
</filterchain>

I end up getting something like:
[concat] <html>
[concat] <head>
[concat] <title>summary</title>
[concat] <link rel="stylesheet" href="summary.css" type="text/css">
[concat] </head>
[concat] <body>
[concat] <a name="overview"></a>
[concat] <center>
[concat] SUMMARYTABLE
[concat] </center>
[concat] ...more HTML here...
[concat] </html>

I'm assuming it's because the file is just one big token - but if I use 
a line tokenizer, will I be able to match regular expressions over 
multiple lines?

Thanks for the help.

Rebhan, Gilbert wrote:
> Hi,
>
> <table[^>/]*>(.*?)</table>
>
> should match :
>
> <table class="summary">foobar</table>
>
> also with more than one attribute
>
> <table class="summary" foo="bar">foobar</table>
>
>
> foobar is  /1  (group 1)
>
>
> Regards, Gilbert
>  
>
> -----Original Message-----
> From: George Bills [mailto:gbills@funnelback.com] 
> Sent: Monday, November 27, 2006 6:41 AM
> To: Ant Users List
> Subject: Re: containsregex and concat
>
> Hrm, it probably isn't since advanced regexs are still black magic to 
> me. The "." was supposed to match any character, including a newline 
> (with the s flag), the * to say match 0-n of them and the ? to say be 
> lazy, match as little as possible (so that I don't pull in 
> <table>...</table><table>...</table> in one match).
>
> I just tried [^<], but it doesn't seem to work - I think because of such
>
> things as "<table><tr>...</tr></table>" - the opening bracket of <tr> 
> conflicts. I tried [.&lt;&gt]*? to make sure that the "regex.body" part 
> was matching the brackets, but that didn't work either.
>
> Also, <table class="summary"> was wrong - <table class="summary"(.*?)> 
> is a little better since the tables can have more than the class 
> attribute (in fact, all of them do). But after changing that I'm 
> matching the entire document - <html> through to </html>. That might 
> just be because I'm using filetokenizer - if I make one match within 
> filetokenizer, do I end up getting the entire document? If so, how do I 
> get only the matching text?
>
> Regex is now: <table class="summary".*?>.*?</table>
>
> Thanks for the help, I appreciate it.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


RE: containsregex and concat

Posted by "Rebhan, Gilbert" <Gi...@huk-coburg.de>.
Hi,

<table[^>/]*>(.*?)</table>

should match :

<table class="summary">foobar</table>

also with more than one attribute

<table class="summary" foo="bar">foobar</table>


foobar is  /1  (group 1)


Regards, Gilbert
 

-----Original Message-----
From: George Bills [mailto:gbills@funnelback.com] 
Sent: Monday, November 27, 2006 6:41 AM
To: Ant Users List
Subject: Re: containsregex and concat

Hrm, it probably isn't since advanced regexs are still black magic to 
me. The "." was supposed to match any character, including a newline 
(with the s flag), the * to say match 0-n of them and the ? to say be 
lazy, match as little as possible (so that I don't pull in 
<table>...</table><table>...</table> in one match).

I just tried [^<], but it doesn't seem to work - I think because of such

things as "<table><tr>...</tr></table>" - the opening bracket of <tr> 
conflicts. I tried [.&lt;&gt]*? to make sure that the "regex.body" part 
was matching the brackets, but that didn't work either.

Also, <table class="summary"> was wrong - <table class="summary"(.*?)> 
is a little better since the tables can have more than the class 
attribute (in fact, all of them do). But after changing that I'm 
matching the entire document - <html> through to </html>. That might 
just be because I'm using filetokenizer - if I make one match within 
filetokenizer, do I end up getting the entire document? If so, how do I 
get only the matching text?

Regex is now: <table class="summary".*?>.*?</table>

Thanks for the help, I appreciate it.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: containsregex and concat

Posted by George Bills <gb...@funnelback.com>.
Hrm, it probably isn't since advanced regexs are still black magic to 
me. The "." was supposed to match any character, including a newline 
(with the s flag), the * to say match 0-n of them and the ? to say be 
lazy, match as little as possible (so that I don't pull in 
<table>...</table><table>...</table> in one match).

I just tried [^<], but it doesn't seem to work - I think because of such 
things as "<table><tr>...</tr></table>" - the opening bracket of <tr> 
conflicts. I tried [.&lt;&gt]*? to make sure that the "regex.body" part 
was matching the brackets, but that didn't work either.

Also, <table class="summary"> was wrong - <table class="summary"(.*?)> 
is a little better since the tables can have more than the class 
attribute (in fact, all of them do). But after changing that I'm 
matching the entire document - <html> through to </html>. That might 
just be because I'm using filetokenizer - if I make one match within 
filetokenizer, do I end up getting the entire document? If so, how do I 
get only the matching text?

Regex is now: <table class="summary".*?>.*?</table>

Thanks for the help, I appreciate it.

Dave Brosius wrote:
> .*?
>
> doesn't seem right to me.
>
> what's that's suppposed to do?
>
> probably something like [^<]*
>
>
>
> ----- Original Message ----- From: "George Bills" <gb...@funnelback.com>
> To: <us...@ant.apache.org>
> Sent: Sunday, November 26, 2006 11:47 PM
> Subject: containsregex and concat
>
>
>> I've been trying to use a regular expression and the concat task to 
>> pull summary tables (<table class="summary">...</table>) out of a set 
>> of test reports. The reports are all HTML files sitting in 
>> ${report.path}. The task works fine up until I start trying to select 
>> output from it with <containsregex>. Is there something wrong with my 
>> regular expression? Is there an easier way to do this? Any help would 
>> be appreciated.
>>
>> The code is:
>> ====================
>> <target name="summary"> <!-- make a report summary -->
>>    <property name="summary.start" value="&lt;table 
>> class=&quot;summary&quot;&gt;" />
>>    <property name="summary.body"  value=".*?" /> <!-- enable "s" for 
>> newline matches -->
>>    <property name="summary.end"   value="&lt;/table&gt;" />
>>    <property name="summary.regex" 
>> value="${summary.start}${summary.body}${summary.end}" />
>>    <echo>${summary.regex}</echo>
>>    <concat>
>>        <header>HEADER</header>
>>        <fileset dir="${report.path}"
>>            includes="*.html"
>>            excludes="${summary.file}" />
>>            <filterchain>
>>                <tokenfilter>
>>                    <filetokenizer />
>>                    <containsregex flags="is"
>>                                   pattern="${summary.regex}" />
>>                </tokenfilter>
>>            </filterchain>
>>        <footer>FOOTER</footer>
>>    </concat>
>> </target>
>> ====================
>>
>> The regular expression echoes as:
>> ====================
>> <table class="summary">.*?</table>
>> ====================
>>
>> I've done some testing of the expression at 
>> http://www.fileformat.info/tool/regex.htm, and it seems to work there.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>> For additional commands, e-mail: user-help@ant.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: containsregex and concat

Posted by Dave Brosius <db...@apache.org>.
.*?

doesn't seem right to me.

what's that's suppposed to do?

probably something like [^<]*



----- Original Message ----- 
From: "George Bills" <gb...@funnelback.com>
To: <us...@ant.apache.org>
Sent: Sunday, November 26, 2006 11:47 PM
Subject: containsregex and concat


> I've been trying to use a regular expression and the concat task to pull 
> summary tables (<table class="summary">...</table>) out of a set of test 
> reports. The reports are all HTML files sitting in ${report.path}. The 
> task works fine up until I start trying to select output from it with 
> <containsregex>. Is there something wrong with my regular expression? Is 
> there an easier way to do this? Any help would be appreciated.
> 
> The code is:
> ====================
> <target name="summary"> <!-- make a report summary -->
>    <property name="summary.start" value="&lt;table 
> class=&quot;summary&quot;&gt;" />
>    <property name="summary.body"  value=".*?" /> <!-- enable "s" for 
> newline matches -->
>    <property name="summary.end"   value="&lt;/table&gt;" />
>    <property name="summary.regex" 
> value="${summary.start}${summary.body}${summary.end}" />
>    <echo>${summary.regex}</echo>
>    <concat>
>        <header>HEADER</header>
>        <fileset dir="${report.path}"
>            includes="*.html"
>            excludes="${summary.file}" />
>            <filterchain>
>                <tokenfilter>
>                    <filetokenizer />
>                    <containsregex flags="is"
>                                   pattern="${summary.regex}" />
>                </tokenfilter>
>            </filterchain>
>        <footer>FOOTER</footer>
>    </concat>
> </target>
> ====================
> 
> The regular expression echoes as:
> ====================
> <table class="summary">.*?</table>
> ====================
> 
> I've done some testing of the expression at 
> http://www.fileformat.info/tool/regex.htm, and it seems to work there.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org