Avatar of DrDamnit
DrDamnit
Flag for United States of America asked on

URL Regex matches non-urls?

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?
Regular ExpressionsPHPPerl

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Marco Gasi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Dan Craciun

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
wilcoxon

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

Open in new window

DrDamnit

ASKER
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!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ray Paseur

Thank, Michael.  All the best, ~Ray