Re: Re: Regex for extracting quoted strings

From: Date: Sat, 05 Mar 2011 22:38:56 +0000
Subject: Re: Re: Regex for extracting quoted strings
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-311705@lists.php.net to get a copy of this message
Hi. Thanks for all the replies. On Saturday 05 Mar 2011 at 22:11 Simon J Welsh wrote: > On 6/03/2011, at 11:08 AM, Shawn McKenzie wrote: > > $regex = '/"([^"]+)"/'; Shawn, this regex gets me two copies of each string - one with and one without the double quotes - as did the one Nathan posted earlier. > Also, you'll want preg_match_all rather than preg_match. Yeah, I realised that quite early on in my messing about. What I have ended up with is: $regex = '/".*?"/'; $found = preg_match_all($regex, $sentence, $phrases); This still leaves the quotes in the phrases, but at least I only get one copy of each phrase. I'm just trimming the quotes afterwards. Thanks for all the advice. Mark

« previous php.general (#311705) next »