[nycphp-talk] Question about REGEX's...
Mark Armendariz
enolists at gmail.com
Tue Nov 28 20:14:39 EST 2006
Is it returning everything between that first div and the last </div> on the
page? If so, it's being 'greedy'. Basically that .+? is matching
everything (including interior </div>'s). You can use the 'Ungreedy'
modifier 'U' (captial u after the final slash) or make your regex between
the divs more specific. Something like ([^<]+) (anything that's not a left
angle bracket) can be ok if you don't expect the left angle bracket to be in
your subject.
manual for modifiers:
http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php
And Mr. Merlo's suggestion about quotes (strange that it doesn't throw an
error without them, no?)
Mark
On 11/28/06, Chris Merlo <chris at theyellowbox.com> wrote:
>
> On 11/28/06, Anthony Papillion <anthony at adcl.biz> wrote:
> >
> > Hello Everyone,
> >
> > I am using the following regex to retrieve text between two <div> tags.
> >
> > $trans_text = preg_match(/<div id=result_box dir=ltr>(.+?)</div>/);
> >
>
> Don't you need to surround the pattern in quotes? I always have.
> -c
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20061128/59bfdd16/attachment.html>
More information about the talk
mailing list