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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:32:59+00:00 2026-05-31T00:32:59+00:00

I am very new to RegExp. Here is my problem. I have an input

  • 0

I am very new to RegExp. Here is my problem. I have an input value. I apply a RegExp “rule” to that input value. The rule is starts with the input value and is not case sensitive. Lets take an example. My reference string is Paris (75018) and my input value is Pari. In that scenario everything is working fine. But if the input value is Paris (7 it is not working. In that case the “system” is telling me no match and I don’t get it. It is matching! Hope someone can help. Thank you in advance for your replies. Cheers. Marc.

http://jsfiddle.net/JU8Va/

My html:

<input id="btn" type="submit" />​

My js:

$('#btn').click(function() {
    var loc = "Paris"; //input value...
    var locRegExp = new RegExp("^" + loc, "i"); // 

    var test = "Paris (75018)"; //reference value

    if (test.match(locRegExp)) {
        alert('matches');
        }
        else {
            alert('does not match');
        }
    });​
  • 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-31T00:33:01+00:00Added an answer on May 31, 2026 at 12:33 am

    The problem is the ( has a special meaning in regular expressions. To get it literally, you have to escape it as \(. See here: http://jsfiddle.net/JU8Va/1/

    var loc = "Paris \\(7";
    var locRegExp = new RegExp("^" + loc, "i");
    

    Note that there is a double backslash; that’s because backslash itself has a special meaning in literal quoted strings, so you have to escape the backslash to get it literally in the regex.

    Also note that for literal (unquoted) regexes, you don’t need to escape the backslash, just the parenthesis. For example: test.match(/Paris \(7/).

    In regular expressions, an unescaped ( means “start a capture group”. Capture groups are the way you retrieve match data after running it. See here for an answer about how those work: http://www.regular-expressions.info/brackets.html

    If you don’t know ahead of time what loc will contain, you can replace all instances of parenthesis with the escaped versions, like this:

    var locRegExp = new RegExp("^" + loc.replace(/\(/g, "\\(").replace(/\)/g, "\\)"), "i");
    

    But be aware that there are many special characters besides parenthesis that you may need to test for. If you find yourself replacing a lot of characters, maybe consider trying a different approach. For example, are you just looking for a case-insensitive search that starts at the beginning of the test string? For that you don’t need regular expressions, you can just do a substring search:

    test.toLowerCase().indexOf(loc.toLowerCase()) === 0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I very new to Python, and fairly new to regex. (I have no Perl
Very new to XSL (and XML for that matter), but I need to step
Very new mobile developer here... I am trying to retrieve a list of tweets
Im very new to all coding including jquery. I though this would have been
I am very new to jQuery and javascript. I have an autocomplete box setup
I'm very new to PDO - only being told to head in that direction
I'm not sure what exactly i'm doing wrong here...but i noticed that my File.Move()
So, I have this JavaScript function: ME.Utils = { RxEmail: new RegExp(/^(([\w-\s]+)|([\w-]+(?:\.[\w-]+)*)|([\w-\s]+)([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i), ValidateEmail: function(email)
I am new to this forum and very new to regexp and rewrites in
I have a text file that contains very long lines. I need one piece

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.