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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:05:09+00:00 2026-05-12T19:05:09+00:00

This regex: ^((https?|ftp)\:(\/\/)|(file\:\/{2,3}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)?)+?)(\.)([a-z]{2} |com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum))([a-zA-Z0-9\?\=\&\%\/]*)?$ Formatted for readability: ^( # Begin regex / begin

  • 0

This regex:

^((https?|ftp)\:(\/\/)|(file\:\/{2,3}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)?)+?)(\.)([a-z]{2}
|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum))([a-zA-Z0-9\?\=\&\%\/]*)?$

Formatted for readability:

^( # Begin regex / begin address clause
  (https?|ftp)\:(\/\/)|(file\:\/{2,3}))? # protocol
  ( # container for two address formats, more to come later
   ((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
   (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?) # match IP addresses
  )|( # delimiter for address formats
   ((([a-zA-Z0-9]+)(\.)?)+?) # match domains and any number of subdomains
   (\.) #dot for .com
   ([a-z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum) #TLD clause
  ) # end address clause
([a-zA-Z0-9\?\=\&\%\/]*)? # querystring support, will pretty this up later
$

is matching:

http://www.google

and shouldn’t be. This is one of my “fail” test cases. I have declared the TLD portion of the URL to be mandatory when matching on alpha instead of on IP, and “google” doesn’t fit into the “[a-z]{2}” clause.

Keep in mind I will fix the following issues seperately – this question is about why it matches http://www.google and shouldn’t.

  • Querystring needs to support proper formats only, currently accepts any combination of querystring characters
  • Several protocols not supported, though the scope of my requirements may not include them
  • uncommon TLDs with 3 characters not included
  • Probably matches http://www.google..com – will check for consecutive dots
  • Doesn’t support decimal IP address formats

What’s wrong with my regex?

edit: See also a previous problem with an earlier version of this regex on a different test case:
How can I make this regex match correctly?

edit2: Fixed – The corrected regex (as asked) is:

^((https?|ftp)\:(\/\/)|(file\:\/{2,3}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}
(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)?)+?)(\.)([a-z]{2}|com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum))([\/][\/a-zA-Z0-9\.]*)*?([\/]?[\?][a-zA-Z0-9\=\&\%\/]*)?$

  • 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-12T19:05:09+00:00Added an answer on May 12, 2026 at 7:05 pm

    “google” might not fit in [a-z]{2}, but it does fit in [a-z]{2}([a-zA-Z0-9\?\=\&\%\/]*)? – you forgot to require a / after the TLD if the URL extends beyond the domain. So it’s interpreting it with “www.go” as the domain and then “ogle” following it, with no slash in between. You can fix it by adding a [?/] to the front of that last group to require one of those two symbols between the TLD and any further portion of the URL.

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

Sidebar

Related Questions

Given this regex: ^((https?|ftp):(\/{2}))?(((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3} (25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(((([a-zA-Z0-9]+)(\.)*?))(\.)([a-z]{2} |com|org|net|gov|mil|biz|info|mobi|name|aero|jobs|museum){1}) Reformatted for readability: @^((https?|ftp):(\/{2}))? + // http://, https://,
I'm using this jquery plugin: https://github.com/maranomynet/linkify/blob/master/1.0/jquery.linkify-1.0.js With this REGEX plugins I'm trying to linkify
I built up this regex at http://regextester.com to parse YSOD but VS is complaining
This is JavaScript regex. regex = /(http:\/\/[^\s]*)/g; text = I have http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd and I
I'm using @diegoperini's regex to validate URL's, However this: http://domain.com/#foo -> Matches http://domain.com#foo ->
preg_replace('/http:///ftp:///', 'https://', $value); http:// and ftp:// inside $value should be replaced with https:// This
I had this url regex pattern in place: $pattern = @\b(https?://[^\s()<>\[\]\{\}]{1,.$max_length_allowed_for_each_url.}(?:\([\w\d]+\)|([^[:punct:]\s]|/)))@; It seemed to
Take a look at this programming challenge. https://gist.github.com/1083219 We’ve built a new communication protocol
I'm looking for a regex that accept urls like these: http://www.example.com www.example.com This is
Tested on regexpal.com this regex works fine, but when run in my program it

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.