Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Robert Oschler
July 31, 2005, 6:23 pm
rate this thread
string. I tried the following:
preg_match_all("/(?:\").*?(?:\")/i", $theString, $matches,
Given the following input string, whose quotes are escaped (slashed):
dogs \"bean bags\" cats \"in quotes\"
I get these two matches:
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
2) Why are the double-quotes still being captured despite my use of
3) Why did only one of the slashes get captured?
Re: REGEX: Quotes still captured, don't want them
The (?:...) syntax does capture the specified character sequences; what you
are really after are assertions:
Mind the [^\s]; I have put it there to distinguish between \"bean bags\" and
\" cats \", which is also captured as a quoted substring otherwise.
Because you didn't mark the backslashes as literal characters, as in:
'/(?:\").*?(?:\")/i' (Also note the single quotes enclosing the pattern)