Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #15760

Re: regexp help

From Jake Jarvis <pig_in_shoes@yahoo.com>
Newsgroups comp.lang.javascript
Subject Re: regexp help
Date 2012-09-07 10:55 +0200
Message-ID <aatr4mFvsbU1@mid.uni-berlin.de> (permalink)
References <fqydnZxNJ4Gw59TNnZ2dnUVZ_sidnZ2d@westnet.com.au>

Show all headers | View raw


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".

-- 
Jake Jarvis

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

regexp help Andrew Poulos <ap_prog@hotmail.com> - 2012-09-07 14:37 +1000
  Re: regexp help Jake Jarvis <pig_in_shoes@yahoo.com> - 2012-09-07 10:55 +0200
    Re: regexp help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-07 15:36 +0200
      Re: regexp help Andrew Poulos <ap_prog@hotmail.com> - 2012-09-08 10:27 +1000
        Re: regexp help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-08 09:34 +0200
      Re: regexp help "Scott Sauyet" <3103invalid@webnews.fastusenet.org> - 2012-09-11 16:51 +0000
        Re: regexp help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-11 22:31 +0200
          Re: regexp help "Scott Sauyet" <3103invalid@webnews.fastusenet.org> - 2012-09-19 11:56 +0000
            Re: regexp help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-19 18:51 +0200
              Re: regexp help Scott Sauyet <scott.sauyet@gmail.com> - 2012-09-19 12:52 -0700
                Re: regexp help Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-09-20 02:13 +0200
                Re: regexp help Scott Sauyet <scott.sauyet@gmail.com> - 2012-09-20 06:51 -0700
                Re: regexp help Dr J R Stockton <reply1237@merlyn.demon.co.uk.invalid> - 2012-09-20 20:23 +0100
      Re: regexp help "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-09-11 14:55 -0700

csiph-web