RegEx: Link not beginning with http://
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.
Boray Eris
Here is a function that I made.
function make_www_link($textvar){
$patterns='/(^|[strn])((www.)+[wd:#@%/;$()~_?+-=\.&]*)/i';
$replacements='$1$2';
$link=preg_replace($patterns,$replacements,$textvar);
return $link;
}
Nicola Brath
I adore your site greatly. Will read more. Keep up to great posting on it. Thank you
jen
thank you so much for this. I was stuck, and now i’m not
what is a hemroid
Excellent website, lover! RegEx: Link not beginning with http:// | mdgArt is actually some thing. I will be establishing acquire soon i will certainly duplicate parts of the one you have, lawfully obviously
jack
thanks for this