REGEX: Quotes still captured, don't want them
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

REGEX: Quotes still captured, don't want them

From: Robert Oschler <no-mail-please@nospam.com>
Date: Sun Jul 31 2005 - 20:23:30 CEST

I am trying to strip out the contents of all double-quoted phrases in a
string. I tried the following:

preg_match_all("/(?:\").*?(?:\")/i", $theString, $matches,
PREG_PATTERN_ORDER);

Given the following input string, whose quotes are escaped (slashed):

dogs \"bean bags\" cats \"in quotes\"

I get these two matches:

"bean bags\"
"in quotes\"

As you can see, I'm still capturing the quotes and one, but curiously not
both, of the slashes.

I want to get just the contents of the string inside the slashed
double-quotes, so here are my questions:

1) How can I get just the contents of the string inside the slashed
double-quotes?

2) Why are the double-quotes still being captured despite my use of
non-capturing parentheses?

3) Why did only one of the slashes get captured?

Thanks
Received on Tue Oct 18 02:06:36 2005