String.replace question

G

glennremar

I was tring to write a function to make that took the letters that a
user is searching for and making the first occurrence of it bold in
the results (ignoring the case).
From reading javascript books and looking at posts in this group, I
thought this would work. Perhaps I misunderstood what $1 is. But in
the results, I am getting a bold $1 with IE6.

How can I determine what the occurrence of the phrase is in the
correct case?

I realize I can write this parsing the string without regular
expressions but I thought this would be cleaner.

var match = new RegExp( escapeCharsForRegExp(typedLetters), "i");
if (match.test(text))
{
text = text.replace(match, '<b>' + '$1' + '</b>' );
}
 
L

Lee

(e-mail address removed) said:
I was tring to write a function to make that took the letters that a
user is searching for and making the first occurrence of it bold in
the results (ignoring the case).

thought this would work. Perhaps I misunderstood what $1 is. But in
the results, I am getting a bold $1 with IE6.

How can I determine what the occurrence of the phrase is in the
correct case?

I realize I can write this parsing the string without regular
expressions but I thought this would be cleaner.

var match = new RegExp( escapeCharsForRegExp(typedLetters), "i");
if (match.test(text))
{
text = text.replace(match, '<b>' + '$1' + '</b>' );
}

$1 is the value of the text that matches the part of the regexp
which is enclosed in the first pair of parentheses. You haven't
shown us your regexp, but I assume it doesn't contain parens.


--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top