Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <3457030.NDG8SBlVoo@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Sat, 08 Sep 2012 09:34:54 +0200 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+&. <1492793.DGNhQbDWfW@PointedEars.de> <0JWdnZHHxY1_DdfNnZ2dnUVZ_vednZ2d@westnet.com.au> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 76 NNTP-Posting-Date: 08 Sep 2012 09:34:55 CEST NNTP-Posting-Host: 145daf8b.newsspool1.arcor-online.net X-Trace: DXC=_GihJR;B_cic==]BZ:afn4Fo<]lROoRankgeX?EC@@`59mb1gI=;^iDZm8W4\YJNlR=i2=[N6Y6j9EE^d\>`76jRmXMK5J45Bh X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:15791 Andrew Poulos wrote: > On 7/09/2012 11:36 PM, Thomas 'PointedEars' Lahn wrote: >> Jake Jarvis wrote: >>> On 07.09.2012 06:37, wrote Andrew Poulos: >>>> I have a string >>>> var str = 'This is some text.'; >>>> >>>> Within that string I need to find whether a whole word exists. The test >>>> is to be case insensitive. The word to test for is held in the var 'k'. >>>> >>>> When I try this: >>>> >>>> var k = 'SOME'; >>>> var myRe = new RegExp("b" + k + "b", "i"); >>>> var found = myRe.test(str); >>>> >>>> I expected 'found' to return true. What am I doing wrong? >>> >>> You are not escaping the two 'b' characters. >>> >>> There are 2 levels here: the level of the regular expression in which >>> you want '\b', and the level of the pattern string in which you need >>> '\\b', because strings have their own escape rules which apply first and >>> under those '\b' means "backspace character", whereas '\\b' means >>> "backslash b". >> >> In addition, \b is not sufficient in most cases as it matches a boundary >> between a "word character" and "not-a-word-character". Word characters >> are those matched by `\w', which in turn is defined as the equivalent of >> [0-9A-Za-z_]. Non-ASCII letters are not included. Even basically >> English text can contain non-ASCII characters (borrowed from or written >> in other languages): > > Hmm, that means that common apostrophe'd words such as "don't" or > "Andrew's" would not be matched. Why don't you try? They would: \b d o n \b ' \b t \b | | | | | | | \b d o n ' t \b The problem is here, for example: \b B a h n \b ü \b b e r g a n g \b ("railroad crossing" in German) | | | | | | \b B a h n \b ("railroad" in German) > BTW is "don't" considered a single word? That depends on how you define a word. With the native \w+: No, because it contains one character that is not a word character, it would be considered two words, and there would be two matches with /\w+/g. >> > from-a-string/8568325#8568325> f. >> >> Which gives me the idea that a Unicode mode for jsx.regexp.RegExp() to >> replace \b, \w and \W – in addition to or using the already implemented >> Unicode character properties (\p{Lu} et al.) – would come in handy. >> Comments anyone? > > I understand what you're suggesting but I don't know enough about the > topic to make suggestions. IOW, would you find it useful to match words containing non-ASCII letters with `new jsx.regexp.RegExp("\\w+", "u")'? PointedEars -- realism: HTML 4.01 Strict evangelism: XHTML 1.0 Strict madness: XHTML 1.1 as application/xhtml+xml -- Bjoern Hoehrmann