Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: Confusion about String.matches method Date: Wed, 01 Jun 2011 08:41:25 -0600 Organization: As little as possible Lines: 37 Message-ID: <2p4o49mx62.fsf@shell.xmission.com> References: <50016a00-9422-46d4-8278-619fedafff55@c41g2000yqm.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="PnllQd880uOddfy6hsxHuQ"; logging-data="14690"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ypaNCbusOiSIATgZVTL8Q" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:jjwTaGo111t3Z1bgx2bUp6Qa/+c= sha1:P3d9RnSbS+wMVK9Gkbo+rRo6Ngg= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4854 laredotornado writes: > On May 31, 12:28 pm, Andreas Leitgeb > wrote: >> laredotornado wrote: >> > Hi, >> > I'm using Java 1.6.  How would I modify my regular expression below >> > ^Starting at \$32,000*$ >> >> ^Starting at \$32,000\*$ >> >> > so that it will match the string, "Starting at $32,000*".  In other >> > words, I have >> > String regEx = "^Starting at \\$32,000*$"; >> >> String regEx = "^Starting at \\$32,000\\*$"; >> >> > String text = "Starting at $32,000*"; >> > if (!text.matches(regEx)) { >> >       throw new RuntimeException("does not match"); >> > } >> > but the exception is always thrown.  Please let me know how can I >> > modify my reg ex to match.  Thanks, - Dave >> >> > > Is there a way I can match an arbitrary string without having to > escape everything? I tried putting my token in quotes ... > > String regEx = "^Starting at (\"$32,000*\")$"; > > but that failed to match. - Dave String regEx= "^Starting at " + Pattern.quote("$32,000*") + "$"; -- Jim Janney