Re: find quoted string within a string (more of a regex question, though ..)
| From: | Wouter van Vliet | Date: | Fri, 10 Sep 2004 13:58:03 +0000 |
| Subject: | Re: find quoted string within a string (more of a regex question, though ..) | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-196307@lists.php.net to get a copy of this message | ||
On Fri, 10 Sep 2004 16:41:56 +0300, Robin Vickery <robinv@gmail.com> wrote:
> On Fri, 10 Sep 2004 11:43:54 +0200, Wouter van Vliet
> <wouter.van.vliet@gmail.com> wrote:
> >
> > For my own reasons (can explain, would take long, won't till sbody
> > asks) I want to match a quoted string within a string. That is somehow
> > kind of easy, I know ... if it weren't for the slashing of quotes.
>
> The standard perl regexp for matching double-quote delimited strings is this:
>
> /"([^"\\]|\\.)*"/
>
> which copes nicely with escaped characters. You'll probably need to
> double up the backslashes in php.
>
> $regex = '/"([^"\\\\]|\\\\.)*"/';
>
Strawberryjuice on earth, I was expecting something very easy - but
this beats it all. Changed it a little, for it to also find
single-quote delimited strings:
/( "([^"\\]|\\.)*" | '([^'\\]|\\.)*' )/x
works like a coconut!
Thanks a lot!
Wouter