Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #13320

Re: Parse a text file and match more than one line

Path csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail
From Knute Johnson <nospam@knutejohnson.com>
Newsgroups comp.lang.java.programmer
Subject Re: Parse a text file and match more than one line
Date Mon, 02 Apr 2012 14:43:17 -0700
Organization A noiseless patient Spider
Lines 71
Message-ID <jld6hl$h5q$1@dont-email.me> (permalink)
References <3e114ac2-7034-4167-8d67-ac869f6643f1@h20g2000yqd.googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 2 Apr 2012 21:43:17 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="mz/LDSJwiWnk3Jnnqg7x+Q"; logging-data="17594"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ekWyYY6A1Pf8bG/7HPeLu"
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:11.0) Gecko/20120327 Thunderbird/11.0.1
In-Reply-To <3e114ac2-7034-4167-8d67-ac869f6643f1@h20g2000yqd.googlegroups.com>
Cancel-Lock sha1:X/5afdjtgLraNPZEWdhfxAxzGRU=
Xref csiph.com comp.lang.java.programmer:13320

Show key headers only | View raw


On 4/2/2012 4:36 AM, mike wrote:
> Hi,
>
> I am trying to figure out how to use regexp in java to match this
> pattern:
>
>
> compile:
>      [javac] Compiling 933 source files to /tmp/gdduser/classes
>
> dft.properties:
>
> So I want to make sure I have:
>
> compile:
>      [javac] Compiling 933 source files to /tmp/gdduser/classes
> <<nothing on this line>>
>
> How can I use java to apply it? It will be something like, when
> "compile:" is found check that there is a [javac] Compiling .... on
> next line . If there is then I need to check if there is an empty
> line. If all conditions are fullfilled then I can I know that my build
> step is completed and I have a full match.
>
> Any ideas?
>
> br,
>
> //mike
>
>
>
>
>

import java.util.regex.*;

public class test {
     static String str = "Hi,\nI am trying to figure out how to use 
regexp in java to match this\npattern:\n\ncompile:\n    [javac] 
Compiling 933 source files to 
/tmp/gdduser/classes\n\ndft.properties:\n\nSo I want to make sure I 
have:\n\ncompile:\n    [javac] Compiling 933 source files to 
/tmp/gdduser/classes\n<<nothing on this line>>\n\nHow can I use java to 
apply it? It will be something like, when\n\n\"compile:\" is found check 
that there is a [javac] Compiling .... on\nnext line . If there is then 
I need to check if there is an empty\nline. If all conditions are 
fullfilled then I can I know that my build\nstep is completed and I have 
a full match.\n\nAny ideas?\n\nbr,\n\n//mike\n";

     public static void main(String[] args) {
         Pattern p = Pattern.compile(
          "(compile:\n\\s+\\[javac\\] Compiling \\d+ source files to .*)");
         Matcher m = p.matcher(str);

         while (m.find())
             System.out.println(m.group(1));
     }
}

C:\Documents and Settings\Knute Johnson>java test
compile:
     [javac] Compiling 933 source files to /tmp/gdduser/classes
compile:
     [javac] Compiling 933 source files to /tmp/gdduser/classes

C:\Documents and Settings\Knute Johnson>

-- 

Knute Johnson

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Parse a text file and match more than one line mike <mikaelpetterson@hotmail.com> - 2012-04-02 04:36 -0700
  Re: Parse a text file and match more than one line Knute Johnson <nospam@knutejohnson.com> - 2012-04-02 14:43 -0700
  Re: Parse a text file and match more than one line Martin Gregorie <martin@address-in-sig.invalid> - 2012-04-02 22:09 +0000
  Re: Parse a text file and match more than one line Jim Janney <jjanney@shell.xmission.com> - 2012-04-02 16:50 -0600
    Re: Parse a text file and match more than one line Jim Janney <jjanney@shell.xmission.com> - 2012-04-02 20:57 -0600
  Re: Parse a text file and match more than one line Roedy Green <see_website@mindprod.com.invalid> - 2012-04-02 15:53 -0700
  Re: Parse a text file and match more than one line Arne Vajhøj <arne@vajhoej.dk> - 2012-04-02 20:08 -0400

csiph-web