We help IT Professionals succeed at work.
Get Started

Word boundarys and highlight text using regular expressions

Last Modified: 2010-04-15
Can anyone help with this small problem.

I can get the text to be highlighted with a match but I'm trying to use word boundaries so that only whole words are highlighted.

My code is:

highlightphrase = Regex.Replace(highlightphrase, "day", "<strong>day</strong>", RegexOptions.IgnoreCase|RegexOptions.Singleline);

Problem is the above is highlighting day in holiday which is incorrect.

I've tried using \< but receive an error stating non reconized escape character also tried using \b but still does not work. I'm using C# and running asp.net.

Any help would be appreciated.
Watch Question
Digital Marketing (Hospitality)
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE