Simple Machines Community Forum

General Community => Scripting Help => Topic started by: zomgwtfbbq on December 26, 2009, 06:18:42 AM

Title: matching a pattern that doesn't..
Post by: zomgwtfbbq on December 26, 2009, 06:18:42 AM
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!
Title: Re: matching a pattern that doesn't..
Post by: Arantor on December 26, 2009, 07:48:55 AM
So what pattern are you using right now?
Title: Re: matching a pattern that doesn't..
Post by: zomgwtfbbq on December 26, 2009, 07:56:55 AM
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
Title: Re: matching a pattern that doesn't..
Post by: 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
Title: Re: matching a pattern that doesn't..
Post by: zomgwtfbbq on December 26, 2009, 08:06:32 AM
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
Thanks brother, ur the best :)