Solved

URL Regex matches non-urls?

Posted on 2014-01-05
6
354 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 30

Accepted Solution

by:
Marco Gasi earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 26

Expert Comment

by:wilcoxon
Comment Utility
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
Comment Utility
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
Comment Utility
Thank, Michael.  All the best, ~Ray
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
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…
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.

772 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

10 Experts available now in Live!

Get 1:1 Help Now