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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:38:41+00:00 2026-05-24T12:38:41+00:00

I found a regular expression that is suppose to capture URLs but it doesn’t

  • 0

I found a regular expression that is suppose to capture URLs but it doesn’t capture some URLs.

$("#links").change(function() {

    //var matches = new array();
    var linksStr = $("#links").val();
    var pattern = new RegExp("^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$","g");
    var matches = linksStr.match(pattern);

    for(var i = 0; i < matches.length; i++) {
      alert(matches[i]);
    }

})

It doesn’t capture this url (I need it to):

http://www.wupload.com/file/63075291/LlMlTL355-EN6-SU8S.rar

But it captures this

http://www.wupload.com

  • 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-24T12:38:41+00:00Added an answer on May 24, 2026 at 12:38 pm

    Several things:

    1. The main reason it didn’t work, is when passing strings to RegExp(), you need to slashify the slashes. So this:

      "^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$"
      

      Should be:

      "^(https?:\/\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\/\\w \\.-]*)*\/?$"
      

    2. Next, you said that FF reported, “Regular expression too complex”. This suggests that linksStr is several lines of URL candidates.
      Therefore, you also need to pass the m flag to RegExp().

    3. The existing regex is blocking legitimate values, eg: “HTTP://STACKOVERFLOW.COM”. So, also use the i flag with RegExp().

    4. Whitespace always creeps in, especially in multiline values. Use a leading \s* and $.trim() to deal with it.

    5. Relative links, eg /file/63075291/LlMlTL355-EN6-SU8S.rar are not allowed?

    Putting it all together (except for item 5), it becomes:

    var linksStr    = "http://www.wupload.com/file/63075291/LlMlTL355-EN6-SU8S.rar  \n"
                    + "  http://XXXupload.co.uk/fun.exe \n "
                    + " WWW.Yupload.mil ";
    var pattern     = new RegExp (
                        "^\\s*(https?:\/\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\/\\w \\.-]*)*\/?$"
                        , "img"
                    );
    
    var matches     = linksStr.match(pattern);
    for (var J = 0, L = matches.length;  J < L;  J++) {
        console.log ( $.trim (matches[J]) );
    }
    

    Which yields:

    http://www.wupload.com/file/63075291/LlMlTL355-EN6-SU8S.rar
    http://XXXupload.co.uk/fun.exe
    WWW.Yupload.mil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XSLT function that takes a regular expression as a parameter but
I found the regular expression for MM/DD/YYYY at http://www.regular-expressions.info/regexbuddy/datemmddyyyy.html but I don't think I
I began studying Java Regular Expression recently and I found some really intersting task.For
I need regular expression that converts links in plain text to HTML links. Here
How can I have a regular expression that tests for spaces or tabs, but
I found this very handy regular expression on regexlib.com, but i'm at a loss
The following javascript code concatenates the matches found by a regular expression. The regular
I need to use a regular expression that contains all the \b characters except
I'm trying to write a regular expression that will essentially return true if string
How to construct a regular expression search pattern to find string1 that is not

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.