Re: 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

Re: REGEX: Quotes still captured, don't want them

From: Janwillem Borleffs <jw@jwscripts.com>
Date: Sun Jul 31 2005 - 22:50:25 CEST

Robert Oschler wrote:
> 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?
>

The (?:...) syntax does capture the specified character sequences; what you
are really after are assertions:

'/(?<=\\\")([^\"]+)[^\s](?=\\\")/i'

Mind the [^\s]; I have put it there to distinguish between \"bean bags\" and
\" cats \", which is also captured as a quoted substring otherwise.

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

Because you didn't mark the backslashes as literal characters, as in:

'/(?:\\\").*?(?:\\\")/i' (Also note the single quotes enclosing the pattern)

JW
Received on Tue Oct 18 02:06:37 2005