Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: simple regex pattern sought Date: Sat, 26 May 2012 17:34:49 +0200 Lines: 50 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net dKHqJ5iiRnV4aXZi/9M9fgQdqkNKkEmUZ/7J7Fa5J532IB39BIimYMbJzyFg506zg= Cancel-Lock: sha1:TGrFKcRPa0MGgn2G1Z6H72Tx7ko= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:12.0) Gecko/20120428 Thunderbird/12.0.1 In-Reply-To: Xref: csiph.com comp.lang.java.programmer:14817 On 26.05.2012 17:06, markspace wrote: > On 5/26/2012 7:37 AM, Robert Klemme wrote: >> On 26.05.2012 03:43, markspace wrote: >>> On 5/25/2012 3:12 PM, Robert Klemme wrote: >>> >>>> "\"(?:\\\\.|[^\\\"])*\"|'(?:\\\\.|[^\\'])*'" >>> > ... >>> and I don't think you need to in a regex >>> either (although I didn't check that). >> >> There is also no regexp escaping of single quotes either. The only >> regexp escaping you can see are the \\\\ which translate into \\ in the >> string which is a literal backslash for the regexp engine. > > > Yes, there is, although I think it's a typo. Both \\\" and \\' get > passed to the regex as \" and \', which means just a single character " > and ' respectively. Right you are - both times: there is regexp escapind and it was in fact a typo (missing \\)! > You're right about the rest of it though. With so many \'s floating > around, I have a hard time reading Java regex! That's true for other languages as well - the basic reason is that the same character is used for - escaping in strings - escaping in backslashes - escaping in the source text (in this case we could pick another character) >> It's not parenthesis around character classes but around the alternative >> of "match a backslash followed by any char" and "any char which is not >> backslash or the opening quote type of this string variant". > > > Yup, I totally missed this too. Thanks for pointing it out. You're welcome! Thank you again for finding the missing escape. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/