List Info

Thread: Regex problem




Regex problem
country flaguser name
United States
2008-03-25 07:07:05

Hi,

I am struggling to create a Regex with boundies "/b" in. I need to search a
textarea and make an exact match for a word. So a search for 'abc' must not
find 'abcc'. I should be simple and there are methods for it but I am not
sure how to construct the Regex. I am having to use this format:

var pattern = new RegExp(document.forms[0].word.value);

when I really want to do

var pattern = /bdocument.forms[0].word.valueb/;

The problem with the latter is that it is treated like a literal '
document.forms[0].word.value' as opposed to the value.

Can anyone offer some advice on how to do this?
Thanx,
Dp.

[Non-text portions of this message have been removed]

__._,_.___
.

__,_._,___
Re: Regex problem
country flaguser name
United States
2008-03-26 04:23:08

At 5:50 PM +0000 3/25/08, Dermot wrote:
>var pattern = /bdocument.forms[0].word.valueb/;

pass a string to new RegExp:

// untested
pattern = new RegExp("\b" + document.forms[0].word.value + "\b")

Emmanuel
Quomodo

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )