Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1795049.zBDcGp28eQ@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 03 Nov 2012 12:26:52 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. <1805042.BzeuYpbCYS@PointedEars.de> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 30 NNTP-Posting-Date: 03 Nov 2012 12:26:52 CET NNTP-Posting-Host: 1edba8f4.newsspool2.arcor-online.net X-Trace: DXC=2fFkXG>SkR>RLigj];iP=8A9EHlD;3Yc24Fo<]lROoR18kFK0M=DB64g7VT0d>>hJc3;TG> X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:17027 Thomas 'PointedEars' Lahn wrote: > […] However, the following can be useful and necessary: > > if ((new RegExp(someOtherString, "i")).test(someString)) > > The caveat in both cases is that any special characters in the value of > `someOtherString' that should not assume their special meaning need to be > escaped. This can be accomplished with a previous replace() – > > if ((new RegExp(someOtherString.replace(/…/g), "i")).test(someString)) Should be if ((new RegExp(someOtherString.replace(/[…]/g, "\\$&"), "i")) .test(someString)) where `…' specifies the (empty-string delimited) list of (special) characters to be escaped (escaped themselves if necessary). The later mentioned user-defined methods are preferable to that, of course. > […] PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee