Solved

URL Regex matches non-urls?

Posted on 2014-01-05
6
362 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
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

691 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