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: Daniele Futtorovic Newsgroups: comp.lang.java.programmer Subject: Re: Confusion about String.matches method Date: Tue, 31 May 2011 23:10:55 +0200 Organization: A noiseless patient Spider Lines: 37 Message-ID: References: <50016a00-9422-46d4-8278-619fedafff55@c41g2000yqm.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 31 May 2011 21:11:02 +0000 (UTC) Injection-Info: mx04.eternal-september.org; posting-host="jLBbZl9RUmNPvzk9IXR8uQ"; logging-data="31428"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jBIiZWeHXcwVZROh2rT6n" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10 In-Reply-To: <50016a00-9422-46d4-8278-619fedafff55@c41g2000yqm.googlegroups.com> Cancel-Lock: sha1:3RCguc/u0loPmYFVgp8vAH6y3As= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4819 On 31/05/2011 22:15, laredotornado allegedly wrote: > 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 "^Starting at (\\Q" + (almost) arbitrary string + "\\E)$" -- DF. Determinism trumps correctness.