matching a pattern that doesn't..

Started by zomgwtfbbq, December 26, 2009, 06:18:42 AM

Previous topic - Next topic

zomgwtfbbq

Hello and first of all happy 2nd xmas day.

I'm trying to convert all urls in a text that aren't surrounded by double-quotes to hyperlinks... no matter what I do I don't get the proper result, either I match every url or nothing.

Any help would be great, cheers!

Arantor

So what pattern are you using right now?
Holder of controversial views, all of which my own.


zomgwtfbbq

Thanks for replying.

I used like I said several preg_replace patterns, the point is that I dont know how I should find content that isn't surrounded by quotes.
If I know that part I can find it out myself.  :D

Arantor

That's why I wanted to see what you had, to see the best way to suggest it.

(?<!foo)bar -> matches bar when not followed by foo
(?!foo)bar -> matches bar when not followed by foo

I think you'll want:
(?<!foo)bar(?!foo)


General reference: http://www.phpguru.org/downloads/PCRE%20Cheat%20Sheet/PHP%20PCRE%20Cheat%20Sheet.pdf
Holder of controversial views, all of which my own.


zomgwtfbbq

Quote from: Arantor on December 26, 2009, 08:05:19 AM
That's why I wanted to see what you had, to see the best way to suggest it.

(?<!foo)bar -> matches bar when not followed by foo
(?!foo)bar -> matches bar when not followed by foo

I think you'll want:
(?<!foo)bar(?!foo)


General reference: http://www.phpguru.org/downloads/PCRE%20Cheat%20Sheet/PHP%20PCRE%20Cheat%20Sheet.pdf [nofollow]
Thanks brother, ur the best :)

Advertisement: