Re: Regular Expressions
| From: | Curt Zirzow | Date: | Tue, 06 Apr 2004 16:02:15 +0000 |
| Subject: | Re: Regular Expressions | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-182489@lists.php.net to get a copy of this message | ||
* Thus wrote Matt Palermo (webmaster@sweetphp.com):
> What exactly does this do:
>
Your original expression:
/< (?!p|br) [^>]* >/x
Find '<' not followed by 'p|br' until the first '>' we find.
<p class="foo"> - matches
< > - matches
Its a bit confusing as why the <p *> matches, perhaps the
documentation at http://php.net/pcre might explain it a little
more.
> /< (?<=p|br) [^>]+ >/x
>
Find '<' until, if 'any charcaters' between, '>' and be sure
that
'p|br' exist before 'any characters'
And perhaps a little more effecient than the one above:
/< (?=p|br) [^>]+ >/x
Find '<', followed by 'p|br' until, if 'any characters' between,
'>'.
The last one probably is a better one since it will fail quickly
whereas look behinds are a bit expensive since it will have to
match < [^>]+ > before it considers the 'p|br'.
> It may work, I just want to understand what it's looking for.
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."