Regex Coach is your friend [http://www.weitz.de/regex-coach/]
I put your regex in there and stepped thru the engine - it's matching
a character to each of the [^\-][^\-][^>] character elements, meaning
you have a one-in-three chance of hitting it just right before
checking for 'Josh'.
-r


On Mon, 17 Jan 2005 13:50:53 -0600, Josh Trutwin
<josh at trutwins.homeip.net> wrote:
> Sorry for the cross post - wasn't sure what the best list to ask this
> was.
> 
> I need a Perl RE to replace a specific HTML comment, something like:
> 
> <!-- blahblahblah Josh blahblahblah -->
> 
> I want to remove all comments with the word Josh in it.  "Josh" could
> be anywhere inside the comment tags.
> 
> Here's what I have (upon removing all line breaks):
> 
> $text =~ s/<!--([^\-][^\-][^>])*?Josh([^\-][^\-][^>])*?-->//g;
> 
> This doesn't match though.  I don't believe I want to use a .*? in
> place of the ([^\-][^\-][^>])*? because there might be many comments
> in a page containing this word and I don't want to replace what's
> between the comments.  Basically an open comment followed by zero or
> more characters that are NOT the closing comment tag sequence,
> followed by Josh, followed by zero or more characters that are not the
> closing comment tag sequence, followed by the closing comment tag.
> The problem is the "not closing comment tag sequence".  Is this not
> the right way to do this?
> 
> Should match:
> 
> <!--Josh-->
> <!--Josh Rules-->
> <!--There goes Josh-->
> <!--Wow, Josh is Cool-->
> 
> I've also tried lookahead assertions, but I'm not very good with
> those, so I'm probably flailing around wildly here:
> 
> $text =~ s/<!--((?:(?!<!--)(?!-->)Josh)*)-->//gx;
> 
> Neither of these seem to do the job.
> 
> Any thoughts / suggestions?
> 
> Thanks,
> 
> Jsoh
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: talk-unsubscribe at tcphp.org
> For additional commands, e-mail: talk-help at tcphp.org
> 
>