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 6374161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:27:13+00:00 2026-05-25T01:27:13+00:00

maybe I’m just misunderstanding Javascript’s regular expression functionality but here goes… I have an

  • 0

maybe I’m just misunderstanding Javascript’s regular expression functionality but here goes… I have an array with expressions I want to remove, and I go about it this way:

var removeThese = ['inc\\.','inc','ltd\\.','ltd','\\(c\\)'];

for(var i=0; i < removeThese.length; i++) {
  var find = removeThese[i];
  regex = new RegExp('\\b'+find+'\\b','gi');
  titletext = titletext.replace(regex,'');
}

So, in the above I expect any island (full word) expressions of inc.,inc,ltd.,ltd or (c) to be matched. My console on console.log(regex):

/\binc.\b/gi
/\binc\b/gi
/\bltd\.\b/gi
/\bltd\b/gi
/\b\(c\)\b/gi

Looks pretty good right? But it’s completely missing any occurances of (c) and when it replaces inc. it leaves the ‘.’, so

This is a title (c) inc.

Becomes

This is a title (c) .

What am I missing here?

note, I would use a reg exp like ‘(inc\.)|(inc)|(ltd\.)…’ but I have some items in that array that need special conversion (like 169 is converted to the © symbol before being searched for.

  • 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-25T01:27:13+00:00Added an answer on May 25, 2026 at 1:27 am

    ( and ) are not considered word characters, so there is no word boundary between whitespace and a (. That means that your \b won’t match there.

    You could change it to something like:

    regex = new RegExp('(^|\\s+)'+find+'(?=\\s+|$)','gi');
    

    Which will remove the word if it is either at the start of the string, or is preceded by some spaces, and at the end of the string, or followed by some spaces. It will also remove the spaces before the string so word (c) word2 will become word_word2 instead of word__word2 (Spaces marked by underscores for clarity).

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

Sidebar

Related Questions

Maybe I just don't know .NET well enough yet, but I have yet to
Maybe this is something obvious, but here is what I have. I need to
Maybe I'm just thinking about this too hard, but I'm having a problem figuring
Maybe world peace would be easier, but I have a problem with the widths
Maybe this is a dumb question, but I have the following behavior in Visual
Maybe i'm just too blind to RTFM but what is the method to call
Maybe the need to do this is a 'design smell' but thinking about another
Maybe this is a dumb question, but is there any way to convert a
Maybe my understanding of agile development isn't as good as it should be, but
Maybe this cannot be done, but please help or suggest how this can be

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.