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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:43:21+00:00 2026-06-07T08:43:21+00:00

My regex successfully validates many URLs except http://www.google Here’s my URL validator in JSFiddle:

  • 0

My regex successfully validates many URLs except http://www.google

Here’s my URL validator in JSFiddle: http://jsfiddle.net/z23nZ/2/

It correctly validates the following URLs:

http://www.google.com gives True

www.google.com gives True

http://www.rootsweb.ancestry.com/~mopoc/links.htm gives True

http:// www. gives False

…but not this one:

http://www.google gives True

It’s not correct to return true in this case. How can I validate that case?

  • 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-07T08:43:23+00:00Added an answer on June 7, 2026 at 8:43 am

    I think you need to way simplify this. There are plenty of URL validation RegExes out there, but as an exercise, I’ll go through my thought process for constructing one.

    1. First, you need to match a protocol if there is one: /((http|ftp)s?:\/\/)?
    2. Then match any series of non-whitespace characters: \S+
    3. If you’re trying to pick out URLs from text, you’ll want to look for signs that it is a URL. Look for dots or slashes, then more non-whitespace: [\.\/]\S*/

    Now put it all together:

    /(((http|ftp)s?:\/\/)|(\S+[\.\/]))\S*[^\s\.]*/
    

    I’m guessing that your attempting to look for www.google is because of the new TLDs… the fact is, such URLs might just look like google, and so any word could be a URL. Trying to come up with a catch-all regex which matches valid URLs and nothing else isn’t possible, so you’re best just going with something simple like the above.

    Edit: I’ve stuck a | in there between the protocol part and the non-whitespace-then-dot-or-slash part to match http://google if people choose to write new URLs like that

    Edit 2: See comments for the next improvement. It makes sure google.com matches, http://google matches, and even google/ matches, but not a..

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

Sidebar

Related Questions

This Regex ([a-zA-Z0-9]?(?:http[s]?://)?(?:(?:\w+)\.)(?:\S+)(?:\.(?:\w+))+?) successfully finds any occurances of http://www.msn.com or www.msn.com or msdn.microsoft.com or
I have successfully created rewrite rules to handle URLs like http://example.com/xyz http://example.com/xyz/ http://example.com/xyz/abc http://example.com/xyz/abc/
Any regex gurus around here? its driving me crazy. Say I have this string:
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
Something like this: http://perl.plover.com/yak/regex/samples/slide083.html In other words I want to match successfully on {
I have successfully created an iHttpModule to replace my Global.asax file in many Web
I am trying to create a .NET Regex to parse a CSS font declaration,
I am sending email from my ASP.net web application. The mails are sending successfully
I am trying to create a RegEx expression that will successfully parse the following
I have the following regex that I have been using successfully: preg_match_all('/(\d+)\n(\w.*)\n(\d{3}\.\d{3}\.\d{2})\n(\d.*)\n(\d.*)/', $text, $matches)

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.