Solved

URL Regex matches non-urls?

Posted on 2014-01-05
6
361 Views
Last Modified: 2014-01-06
This regex:

(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\??(([a-zA-Z0-9]*=[a-zA-Z0-9]*)&?)*\/?

Open in new window


matches URLs quite nicely, but it is failing on this line:

I know that but your name is not on the list see... http://screencast.com/t/ccccccc

It is matching the [see... http] part.

What's wrong?
0
Comment
Question by:DrDamnit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 250 total points
ID: 39757635
This seems to work:

(http(s)*:\/\/)([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\??(([a-zA-Z0-9]*=[a-zA-Z0-9]*)&?)*\/?

Open in new window

0
 
LVL 110

Assisted Solution

by:Ray Paseur
Ray Paseur earned 250 total points
ID: 39757651
MM: The entire article may be a little TL;DR but if you move down quickly to the code samples you can see how I addressed the issue.  Please post back if you still have questions, ~Ray

http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_7830-A-Quick-Tour-of-Test-Driven-Development.html
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39757659
Remove the second ? (instead of (https?:\/\/)? use (https?:\/\/)).

What was the point of it, anyway? 0 or 1 times the group http:// or https:// ???

HTH,
Dan
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 26

Expert Comment

by:wilcoxon
ID: 39758428
What about this?  No reason to reinvent the wheel.
use Regexp::Common qw(URI);
/$RE{URI}{HTTP}/

Open in new window

0
 
LVL 32

Author Closing Comment

by:DrDamnit
ID: 39758449
MarqusG: That does it. Why did your change work?
Ray: Read the whole article. A well written approach, and your use of whitespace to make regexes legible is brilliant. Whitespace is something that I have never really taken full advantage of. Points for the valuable insight!
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 39759299
Thank, Michael.  All the best, ~Ray
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question