Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Eric Sosman Newsgroups: comp.lang.java.programmer Subject: Re: Regex? Date: Fri, 20 Jun 2014 11:14:20 -0400 Organization: A noiseless patient Spider Lines: 40 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Fri, 20 Jun 2014 15:14:24 +0000 (UTC) Injection-Info: mx05.eternal-september.org; posting-host="bd4e1cba8d8592bec5d5ed9e4537fbfd"; logging-data="6822"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PoVKHlwoBNXp0Hr0chSFr" User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 In-Reply-To: Cancel-Lock: sha1:3XLYEXYgH9E//pHb7yuilQIJ/FI= Xref: csiph.com comp.lang.java.programmer:28796 On 6/20/2014 11:06 AM, Knute Johnson wrote: > On 6/20/2014 00:25, Robert Klemme wrote: >> On 06/20/2014 07:03 AM, Knute Johnson wrote: >>> Pattern.compile(Pattern.quote("the string with the ) in it")); >> >> There are more ways: >> >> Pattern.compile("the string with the \\) in it"); >> Pattern.compile("the string with the \\Q)\\E in it"); >> >> Cheers >> >> robert > > Thanks Robert, > > The problem was actually > > String str = "(something"; > Pattern.compile(str); > > so now it is > > Pattern.compile(Pattern.quote(str)); > > I hate to make them > > Pattern.compile(str+"\\Q") > > (the cognoscenti would have my ...) Something seems peculiar: If the cognoscenti who provide the search strings want all characters to stand for themselves and not to function as regex metacharacters, what's the point of using a regex? Why not use theString.indexOf(str)? Is there more to the use case than we've been told? -- Eric Sosman esosman@comcast-dot-net.invalid