[PHP] Match anything between two that is not a except if it is escaped...

2008-01-17 Thread mathieu leddet
Hi everyone,

I am struggling with regular expression trying to match strings
delimited by double quotes, but taking into consideration that \ is not
a string ending character.

---8---
-

$in = 'this is a string : Hi everyone my name is \Mathieu\! Here is
a second string : PHP is just perfect';

// pattern for catching strings between 
$pattern = '#([^]*)#';

// surround matching string with HTML span code to highlight
$replacement = 'b${1}/b';

// perform the reg exp replacement
$out = preg_replace($pattern, $replacement, $in);

---8---
-

$out contains : 
this is a string : bHi everyone my name is \/bMathieu\b!/b
Here is a second string : bPHP is just perfect/b

This behaviour is normal considering my pattern (anything between two 
that is not a ).
But I don't know how to get this :
this is a string : bHi everyone my name is \Mathieu\!/b Here is
a second string : bPHP is just perfect/b

I would like my pattern to express : Anything between two  that is not
a  except if it is escaped.

Thanks for reading me, any help in return is welcome !


--
Mathieu

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Match anything between two that is not a except if it is escaped...

2008-01-17 Thread Jochem Maas

mathieu leddet schreef:

Hi everyone,

I am struggling with regular expression trying to match strings
delimited by double quotes, but taking into consideration that \ is not
a string ending character.


STFW for the concept look behind assertion - that is what you need to
differentiate between an escaped double-quote and the delimiting double quote.



---8---
-

$in = 'this is a string : Hi everyone my name is \Mathieu\! Here is
a second string : PHP is just perfect';

// pattern for catching strings between 
$pattern = '#([^]*)#';

// surround matching string with HTML span code to highlight
$replacement = 'b${1}/b';

// perform the reg exp replacement
$out = preg_replace($pattern, $replacement, $in);

---8---
-

$out contains : 
this is a string : bHi everyone my name is \/bMathieu\b!/b

Here is a second string : bPHP is just perfect/b

This behaviour is normal considering my pattern (anything between two 
that is not a ).
But I don't know how to get this :
this is a string : bHi everyone my name is \Mathieu\!/b Here is
a second string : bPHP is just perfect/b

I would like my pattern to express : Anything between two  that is not
a  except if it is escaped.

Thanks for reading me, any help in return is welcome !


--
Mathieu



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php