RegEx: Link not beginning with http://

Posted on the January 23rd, 2009 under PHP by Mauro

I had to find a regex to match not a string that contain something, but a string that not contain something, and in particular i had to check that a link entered in a form does not begin with http://. I needed to use a regex for this that work with PHP and, i have to admin, it was not so simple.
The method that i found is based on lookahead technique, but seem to work only with preg_match() and not with ereg(). Is not perfect, because it don’t match any string that contain http://, not only that begin with.
This is the regex:


(^((?!.*http\://).)*$)

This match www.ciao.com, but not http://www.ciao.com and also not www.ciao.com/http:// and any string that contain http://. It work for my needs, but is not what really wanted to achieve.
If you know a method to correct the regex, please tell me.

Donate 1 euro, buy me a coffee, I need it to write more posts! Thanks ;)

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Furl
  • Netvibes
  • Pownce
  • Reddit
  • StumbleUpon
  • Technorati
  • TwitThis
  • LinkedIn
  • Ma.gnolia
  • MySpace
Tags: , , , , ,

2 Responses to 'RegEx: Link not beginning with http://'

  1. September 28, 2009 at 7:12 pm
    Boray Eris
  2. March 17, 2010 at 7:14 am
    Nicola Brath

Leave a Reply




XHTML::
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">