Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 843591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:09:11+00:00 2026-05-15T06:09:11+00:00

A colleague asked me about a Regular expression problem, and I can’t seem to

  • 0

A colleague asked me about a Regular expression problem, and I can’t seem to find and answer for him.

We’re using boundaries to highlight certain lengths of text in a text editor, but here’s some sample code that shows the problem:

<script type="text/javascript">
var str = "Alpha , Beta, Gamma Delta Epsilon, AAlphaa, Beta Alpha<br/>";
var rx = new RegExp('\bAlpha\b','gim');

document.write(str.replace(/\b(Alpha)\b/gim, '-- $1 --'));
document.write(str.replace(rx, '== $1 =='));
</script>

The issue is, the first literal str.replace works, but the RegExp option doesn’t.

I’ve got the same behaviour in IE and FF, anyone know why ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:09:12+00:00Added an answer on May 15, 2026 at 6:09 am

    I’m guessing it doesn’t work because you need to escape the backslashes in your string that you pass to RegExp. You have this:

    var rx = new RegExp('\bAlpha\b','gim');
    

    You need this:

    var rx = new RegExp('\\bAlpha\\b','gim');
    

    The string you passed to RegExp has 2 backspace characters in it, since \b is the escape sequence for inserting a backspace into a string. You need to escape each backslash with another backslash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am asked by one of colleague about the Throwable class in java API.
Yesterday, I have a discussion with my colleagues about HTTP. It is asked why
A colleague recently asked me how to deep-clone a Map and I realized that
My colleague insists on explicitly specifying the namespace in code as opposed to using
A colleague asked me the following question the other day. In the following piece
A colleague of mine asked me to take a look at some cookie behaviour.
I have been asked to setup a course leaflet system for a college. For
a colleague pointed me the other day to BCEL which , as best I
My colleague has found himself in an interesting situation. He is working on a
A colleague once told me that the last option when everything has failed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.