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

  • Home
  • SEARCH
  • 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 8278249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:56:48+00:00 2026-06-08T08:56:48+00:00

I have made this regular expression which does exactly what I want when I

  • 0

I have made this regular expression which does exactly what I want when I test it in e.g. RegExr:

^https?:\/\/(www\.)?(test\.yahoo\.com|sub\.yahoo\.com)?(?!([a-z0-9]+\.)?(localhost|yahoo\.com))(.*)?

However when I test it in javascript it says that the expression is invalid. After hours of debugging I found out that this expression works in javascript:

^https?:\/\/(www\.)?(test\.yahoo\.com|sub\.yahoo\.com)?(?![a-z0-9]+\.)?(localhost|yahoo\.com)(.*)?

However this doesn’t do what I want (again testing in RegExr).

Why cannot I use the first expression in javascript? And how do I fix it?

UPDATE JULY 25

Sorry for the lack of info. The way I am using the Regexp is through a jQuery extension which lets me select using regexp. The script can be seen here: http://james.padolsey.com/javascript/regex-selector-for-jquery/

The specific code I am trying to get to work is:

$('a:regex(href, ^https?:\/\/(www\.)?(test\.yahoo\.com|sub\.yahoo\.com)?(?!([a-z0-9]+\.)?(localhost|yahoo\.com))(.*)?)').live('click', function(e) {

After including the linked jQuery plugin. The text strings I am testing are:

  • http://yahoo.com
  • http://google.dk
  • http://subdomain.yahoo.com
  • http://test.yahoo.com
  • http://localhost.dk
  • http://sub.yahoo.com/lalala

Where it is supposed to match “http://google.dk”, “http://test.yahoo.com” and “http://sub.yahoo.com/lalala” – which it does when using RegExr but failing (invalid expression) using the jQuery plugin.

  • 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-08T08:56:51+00:00Added an answer on June 8, 2026 at 8:56 am

    The first regular expression is not invalid:

    var regexp = /^https?:\/\/(www\.)?(test\.yahoo\.com|sub\.yahoo\.com)?(?!([a-z0-9]+\.)?(localhost|yahoo\.com))(.*)?/;
    

    works fine.

    If you want to instantiate the expression from a string, you have to double all the backslashes:

    var regexp = new RegExp("^https?:\\/\\/(www\\.)?(test\\.yahoo\\.com|sub\\.yahoo\\.com)?(?!([a-z0-9]+\\.)?(localhost|yahoo\\.com))(.*)?");
    

    When you start from a string, you have to account for the fact that the string constant itself uses backslashes as a quoting mechanism, so there will be two evaluations made: one as a string, and one as a regular expression.

    edit — OK I think I see the problem. That plugin you’re trying to use is simply attempting to do something that’s just not going to work, given the way that Sizzle parses selectors. In other words, the problem is not with your regular expression, it’s with the overall selector. It is not even getting far enough to parse the regular expression.

    Specifically it seems to be nested parentheses inside the regular expression. Something as simple as

    $('a:regex(href, ((abc)))')
    

    causes an error. You can instead do something like this:

    $('a').filter(function() {
      return /^https?:\/\/(www\.)?(test\.yahoo\.com|sub\.yahoo\.com)?(?!([a-z0-9]+\.)?(localhost|yahoo\.com))(.*)?/.test(this.href);
    }).whatever( ... );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have made a simple php contact form following this tutorial: http://www.catswhocode.com/blog/how-to-create-a-built-in-contact-form-for-your-wordpress-theme The big
Hi have made this function which is made to replicate an error that I
I have made this webpage, you can check it out here http://www.bettingtowin.net/webcam.html I have
I have this regular expression: @(?i)\b(?:p(?:ost)?\.?\s*[o0](?:ffice)?\.?\s*b?(?:[o0]x)?|b[o0]x) Can someone help me identify the issue and
I have this problem which made my scratch my head: Is there a way
Here's my scenario: I have made a regular DLL in C++ (using VS2008) which
I have this custom made site using Jekyll: http://madhur.github.com/ When I view this site
I'm trying to improve a regular expression. I have this string: String myString =
I've a method test that does not have a clear assert expression. The returned
I have made this code: var foo=document.createElement(div); var childs=foo.getElementsByTagName(*); console.log(childs.length);//0 OK var a=document.createElement(a); foo.appendChild(a);

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.