Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: markspace <-@.> Newsgroups: comp.lang.java.programmer Subject: Re: regex capability Date: Tue, 05 Apr 2011 10:07:21 -0700 Organization: A noiseless patient Spider Lines: 42 Message-ID: References: <8vun3sFs1lU1@mid.individual.net> <3fc6e9f5-cf25-44f5-885e-48129ae2e8b3@e9g2000vbk.googlegroups.com> <29adb57e-c515-4859-910c-6393ac812fa6@1g2000yqq.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 5 Apr 2011 17:07:34 +0000 (UTC) Injection-Info: mx03.eternal-september.org; posting-host="FCLJQ+uDFytOOg5Nkz80tA"; logging-data="16894"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/lT8iba/X6IM2ZesunqkQkDcGUyXl01k=" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 In-Reply-To: <29adb57e-c515-4859-910c-6393ac812fa6@1g2000yqq.googlegroups.com> Cancel-Lock: sha1:egxnZoFh/vLZGw/Nhz9ikpgNTfA= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:2888 On 4/5/2011 6:33 AM, Robert Klemme wrote: >>> On Apr 5, 2:35 am, markspace<-@.> wrote: >>>> Why re-invent the wheel? > > In this case I just wanted to demonstrate the strategy to first check > overall validity of the input and extract the interesting part and > then ripping that interesting part apart. Whether a Scanner or > another Matcher is used for the second step wasn't that important to > me. Also, the thread is called "regex capability". :-) Fair enough. :) > > But, of course, your approach using the Scanner is perfectly > compatible with the two step strategy as Patricia also pointed > out. :-) Don't forget too that Scanner can do other things besides use delimiters. It has methods like skip() and findInLine() that ignore delimiters and could be used to build a simple parser. You can also change the delimiters on the fly to extract different sections of text. A simple change to my example above: public class ScannerTest { public static void main(String[] args) { StringReader in = new StringReader( "Support DDR2 100/200/300/400 DDR2 SDRAM"); Scanner scanner = new Scanner(in); scanner.findInLine( "Support DDR2" ); scanner.useDelimiter( "[ /]+" ); while( scanner.hasNextInt() ) { System.out.println( scanner.nextInt() ); } } }