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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:19:31+00:00 2026-06-06T02:19:31+00:00

I have a regex I’m running to filter rows in a table. The filtering

  • 0

I have a regex I’m running to filter rows in a table. The filtering is done in Javascript.

I’m writing coffeescript, but a Javascript solution would be fine — I can just translate it to coffeescript myself.

I have a value role that contains a string I want to filter on using a regex. The problem is the string role may or may not have embedded ‘+’ signs in it. Plus signs are special characters for regex searches and need to be escaped in the search string.

I create the regex search string like this (coffeescript):

"^"+role+"$"

How can I preprocess role to escape any ‘+’ signs so the regex works?

  • 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-06-06T02:19:33+00:00Added an answer on June 6, 2026 at 2:19 am

    + is far from the only character with special meaning. Here is a function that will escape all the necessary characters:

    function regex_escape(str) {
        return str.replace(new RegExp('[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\-]', 'g'), '\\$&');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this regex/javascript code: toReturn = toReturn.replace(/(\[url=)(.+)(\])(.+)(\[\/url\])/g, '<a target=\_blank\ href=\$2>\$4</a>'); But the problem
I have this regex working but now need to allow numbers without the decimal
I have the regex to validate uk phone numbers but it is currently forcing
I have this regex on Javascript : var myString=aaa@aaa.com; var mailValidator = new RegExp(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*);
i have regex code: <script type=text/javascript> var str = kw-xr55und; var patt1 = /[T|EE|EJU].*D/i;
I have a regex \([0-9]+|\-)\ which either takes a number or a hyphen. but
I have this regex working when I test it in PHP but it doesn't
I have that regex to catch any url in php : ((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?) but it
I have a Regex based whitespace filter on an ASP.NET MVC application, and it
here we go. i want to have regex for double number. but not only

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.