Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Some regexp problems Date: Mon, 2 Apr 2012 12:48:39 -0700 (PDT) Organization: http://groups.google.com Lines: 33 Message-ID: <13964491.992.1333396119359.JavaMail.geo-discussion-forums@pbgr6> References: <2048846a-7678-4d0e-b76f-38670934297d@m16g2000yqc.googlegroups.com> NNTP-Posting-Host: 69.28.149.29 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1333396239 11639 127.0.0.1 (2 Apr 2012 19:50:39 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 2 Apr 2012 19:50:39 +0000 (UTC) In-Reply-To: <2048846a-7678-4d0e-b76f-38670934297d@m16g2000yqc.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Received-Bytes: 2359 Xref: csiph.com comp.lang.java.programmer:13317 laredotornado wrote: > I'm using Java 6. I'm trying to write a regexp, which is failing, but > I can't figure out why (same expression works in Perl). Here is my > code ... > > final Pattern addPattern = Pattern.compile("\\s*ADD\\s+([^\\s]+)\ > \s*", Pattern.MULTILINE); Why do you use such exorbitant, unreadable indentation for Usenet posts? You've been around a while and really ought to know better. Do you _want_ to discourage people from answering? Come on, man. > final Matcher addMatcher = addPattern.matcher(cellValue); > > but the call "addMatcher.matches()" returns false for Strings that > look like they match to me. Here is one of them > > cellValue = "ADD 6CCRASR.1 ADD 6CCRASR.2 ADD > 6CCRASR.3 ADD 6CCRASR.5 ADD 6CCRASR. > 10 ADD 6CCRASL.3 ADD 6CCRASL.5\nADD 6RSL. > 1\nADD 6RSL.2\nADD 6RSL.3\nADD 6RSL.5\nADD 6RSL.10\nADD 6RSIT.1\nADD > 6RSIT.2\nADD 6RSIT.3\nADD 6RSIT.5\nADD 6RSIT.10\nADD 6LS.5.b " > > The "\n"'s are newline characters. Any idea what is wrong with the > above regexp or my code? The indicated regex does not match that string. It only matches a substring of that string. Check out the Javadocs for 'Matcher' for alternatives. -- Lew