RE: Little regex help please...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Jim Lucas [mailto:lists@xxxxxxxxx]
> Sent: Monday, October 13, 2008 12:13 PM
> To: Ryan S
> Cc: Eric Butera; Boyd, Todd M.; php php
> Subject: Re:  Little regex help please...
> 
> Too quick on the reply....
> 
> forgot not to escape the forward slash on the closing title tag
> 
> preg_match('#<title>([^<]*)</title>#iU',$data,$match);

That'll do, Jim. :)

I also thought it worth mentioning that by telling a catch-all character
sequence (.*) not to be "greedy", another viable solution would be this:

preg_match('#<title>(.*?)</title>#iU', $data, $match);

The ? will stop it when it reaches </title> through back-tracking.
Probably less-efficient in more complex regex patterns, but I find it
can help make the patterns more readable at-a-glance in regex-heavy code
blocks.

Sorry.. a bit OT.. and the OP has already been answered. Meh.


Todd Boyd
Web Programmer




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux