Re: Some RegEx help please
| From: | Monte Ohrt | Date: | Wed, 20 Sep 2000 21:01:57 +0000 |
| Subject: | Re: Some RegEx help please | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-17263@lists.php.net to get a copy of this message | ||
preg_replace() can do lookaheads and lookbehinds, that will do what you
want.
for example:
Bill(?= The Cat| Clinton)
will match "Bill The Cat" or "Bill Clinton"
Bill(?! The Cat| Clinton)
will match Bill as long as it is not followed by " The Cat" or "
Clinton"
Joe Sheble aka Wizaerd wrote:
>
> Actually, I guess I left something out, but before I dive into that, this
> won't work if it's the first thing in a string because of the space at the
> begin of the search pattern...
>
> BUT, this won't quite work for me because this interferes with legitimate
> URLS in the given text.
>
> If my text is as follows, I only want the URLs that are not already
> surrounded by an <A HREF=""> tag to be converted
>
> $cBlah = "this <A HREF="úb�å€ù
> ÝÆèýhttp://www.somepage.com">tag</A> would not convert,
> but this one http://www.someotherpage.com would
> convert...";
>
> And the same thing applies to email addresses as well.....
>
> At 03:34 PM 9/14/00, James Atkinson wrote:
> >This should do it, I found it at www.phpwizard.net
> >
> >function make_clickable($text) {
> > $ret = eregi_replace("
> > ([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])", "<a
> > href=\"\\1://\\2\\3\" target=\"_blank\"
> > target=\"_new\">\\1://\\2\\3</a>", $text);
> > $ret = eregi_replace("
> > (([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))", "<a
> > href=\"mailto:\\1\"
> > target=\"_new\">\\1</a>", $ret);
> > return($ret);
> >}
> >
> >It'll do email address's and URLS.
>
> On Thu, 14 Sep 2000, Joe Sheble aka Wizaerd wrote:
> > I know I'm real light on the regular expression stuff, and it's my own
> > fault, but I'm working under a fairly heavy deadline, otherwise I'd just
> > find the answer myself.
> >
> > I need a regular expression that finds all web URLs in a given string and
> > converts it to a clickable link. All URLs, even including GET based
> > parameters as well. COuld somebody help me out with this, or point to me a
> > place where I could find such a beast? I've looked on some of the various
> > PHP resources on the net, but I never know what to search for when
> > searching for such a script...
>
> Joseph E. Sheble
> aka Wizaerd
> =============================
> Wizaerd's Realm
> http://www.wizaerd.com
> =============================
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net