Java Mailing List Archive

http://www.ant-tasks.com/

Apache Ant Archive

» Ant Users List
» Ant Developers List
containsregex and concat

containsregex and concat

2006-11-28       - By Rebhan, Gilbert
Reply:     1     2     3     4     5     6     7     8     9     10  


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@(protected)]
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@(protected)]
> 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@(protected)
> For additional commands, e-mail: user-help@(protected)
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)


©2008 ant-tasks.com - Jax Systems, LLC, U.S.A.