On Mon, Jul 31, 2006 at 12:10:26AM +0100, Nicklas Persson wrote:
> Hi
> 
> I'm trying to write a pattern that catches every occurrence of a word as long 
> as
> that word is not inside an html tag.
> 
> e.g I want to catch `Hello World` but not <img title="Hello World" />
> 
> The closest I got was 
> 
> (?!<.*?)Hello World(?![^<>]*?>) 

The first part, (?!<.*?), isn't actually doing anything for you there.
You're basically saying: whatever comes next can't start with <, and must
be Hello World.  Hello World already doesn't start with <, so the negative
look-ahead is redundant.


> which works OK in BBEdit search, but, and here's where I apologise for 
> possibly
> taking this question off topic - not in a PHP page 
> (where it looks like this: $pattern = "'(?!{.*?)$string(?![^{}]*?})'si"; )
> where I'm using it to highlight certain words.
>  
> Does anyone with a lot more experience with regular expressions know the (more
> than likely obvious) way to make this work in PHP too?

BBEdit and PHP both use Perl-Compatible Regular Expressions, so I don't
know why it's not working for you in PHP.  Perhaps you could show a little
more of the code you're using?


Ronald

-- 
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to