Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1373174.86QkPN8Rvz@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sun, 13 Jan 2013 00:49:43 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit Subject: Re: Need regexp help Newsgroups: comp.lang.javascript References: <16779241.CEys5BfS3R@PointedEars.de> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 48 NNTP-Posting-Date: 13 Jan 2013 00:49:44 CET NNTP-Posting-Host: 3bc3941d.newsspool3.arcor-online.net X-Trace: DXC=k8?k^VlC6<285[]]\]T081McF=Q^Z^V384Fo<]lROoR18kFDZm8W4\YJNYBYU3JEo=Nj2W\RHPO>: X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:18097 Thomas 'PointedEars' Lahn wrote: > […] In this exceptional case a *single* regular expression would be > appropriate to parse CSS because the probability of a false positive for > pattern matching can be reduced to close to zero. Watch for word-wrap (or > instead use RegExp.prototype.concat(), provided by jsx.regexp.concat() > [1]): > > css = css.replace(/(^|\s*)body\s*\{\s*font-family\s*:\s*"Courier New", > \s*Courier,\s*monospace;\s*font-size\s*:\s*9pt;\s*valign\s*:\s*top; \s*text- > align\s*:\s*left;\s*line-height:\s*9pt\s*\}\s*td\s*\{\s*font-family\s*: > \s*"Courier New",\s*Courier,\s*monospace;\s*font-size\s*:\s*9pt; > \s*valign\s*:\s*top;text-align\s*:\s*left;\s*line-height:\s*9pt\s*\}/g, > "$1"); > > This begs the question, however, why the OP thinks this would be necessary > here in the first place. I certainly would not recommend it. A better readable version of this: var css = …; var needle = 'body { font-family : "Courier New", Courier, monospace;' + " font-size : 9pt; valign : top; text-align : left;" + " line-height: 9pt }" + ' td { font-family : "Courier New", Courier, monospace;' + " font-size : 9pt; valign : top; text-align : left;" + " line-height: 9pt }"; var rxNeedle = new RegExp( "(^|\\s*)" + needle.replace(/("[^"]*")|\s+/g, function (match, doubleQuoted) { return doubleQuoted || "\\s*"; }).replace(/[{}]/g, "\\$&"), "g"); css = css.replace(rxNeedle, ""); See also RegExp.prototyp.escape() provided by jsx.regexp.escape(). [1] > _________ > [1] -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.