Path: csiph.com!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: Parse a text file and match more than one line Date: Mon, 02 Apr 2012 20:57:45 -0600 Organization: thinking of Maud you forget everything else Lines: 49 Message-ID: <2pr4w534k6.fsf@shell.xmission.com> References: <3e114ac2-7034-4167-8d67-ac869f6643f1@h20g2000yqd.googlegroups.com> <2pvclh3g0e.fsf@shell.xmission.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="PnllQd880uOddfy6hsxHuQ"; logging-data="14081"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wLr7g185Jktv3FmGCEGlz" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:FgtfbQTBVXKPWMmfnvIj3wF5kNM= sha1:58cW9+jPs30Z/AqAUgkuBWCf6WA= Xref: csiph.com comp.lang.java.programmer:13341 Jim Janney writes: > mike writes: > >> 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 >> <> >> >> 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 > > If the file is not too large, you can read it all into a single string > and apply a regexp to that. Or... A matcher needs a CharSequence, not a string, and you can build a CharSequence from a ByteBuffer, and you can map a ByteBuffer directly to a file. Put it all together and you get something like this: http://www.java2s.com/Code/Java/File-Input-Output/ApplyingRegularExpressionsontheContentsofaFile.htm I'd guess this could be horribly expensive for some kinds of patterns. -- Jim Janney