Solved

URL Regex matches non-urls?

Posted on 2014-01-05
6
356 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
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 108

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 34

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 108

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

867 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now