Re: Little regex help please...

From: Date: Mon, 13 Oct 2008 17:13:41 +0000
Subject: Re: Little regex help please...
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-281830@lists.php.net to get a copy of this message
On Mon, Oct 13, 2008 at 1:04 PM, Boyd, Todd M. <tmboyd1@ccis.edu> wrote: >> -----Original Message----- >> From: Eric Butera [mailto:eric.butera@gmail.com] >> Sent: Monday, October 13, 2008 12:00 PM >> To: Boyd, Todd M. >> Cc: Ryan S; php php >> Subject: Re: [PHP] Little regex help please... >> >> On Mon, Oct 13, 2008 at 12:52 PM, Boyd, Todd M. <tmboyd1@ccis.edu> >> wrote: >> > I don't believe you need both the / and the # for delimiters in your >> > RegEx. Try using just # (since / is actually going to be in the text >> > you're searching for) like this: >> > >> > <?php >> > $data = >> > >> > file_get_contents("http://www.youtube.com/watch?v=oQ2dKXGAjNg"); >> > preg_match('#<title>([^<]*)</title>#iU', $data, $match); >> > $title = $match[1]; >> > echo $title; >> > ?> >> >> You can also escape the / like \/. > > Very true... but I think everything gets a bit convoluted when you escape your forward-slashes > instead of just choosing a more convenient delimiter--especially when URLs are involved. I've > seen a few regex that look ridiculous for that very reason: > /http:\/\/www\.asdf\.com\/blah\/foobar\.php/i ... looks like a > zig-zaggy mess. :) > > My 2c, > > > Todd Boyd > Web Programmer > > > > Well that is a bit extreme, but I understand your point. If it were 1 character I'd still stick with /'s and escape one though.

« previous php.general (#281830) next »