On 15 March 2011 10:32, Richard Quadling <[email protected]> wrote:
> On 14 March 2011 20:36, Hannes Landeholm <[email protected]> wrote:
>> What is more likely to be wrong? Your understanding of a specific
>> regex pattern (which happens to be full of escapes making it
>> incredibly hard to read) or the implementation of preg_replace?
>>
>> ~Hannes
>>
>> On 14 March 2011 16:18, Martin Scotta <[email protected]> wrote:
>>>
>>> I chose the simplest example to show the preg_replace behavior, there are
>>> better (and safer) ways to scape slash characters.
>>> Anyways, *is this the expected preg_replace behavior?*
>>>
>>> Martin
>>>
>>> <?php
>>> function test($str) {
>>> static $re = '/(^|[^\\\\])\'/';
>>> static $change = '$1\\\'';
>>>
>>> echo $str, PHP_EOL,
>>> preg_replace($re, $change, $str), PHP_EOL, PHP_EOL;
>>> }
>>>
>>> test("str '' str"); // bug?
>>> test("str \\'\\' str"); // ok
>>> test("'str'"); // ok
>>> test("\'str\'"); // ok
>>>
>>> ----
>>> Expected:
>>>
>>> str '' str
>>> str \'\' str
>>>
>>> str \'\' str
>>> str \'\' str
>>>
>>> 'str'
>>> \'str\'
>>>
>>> \'str\'
>>> \'str\'
>>>
>>> ----
>>> Result:
>>>
>>> str '' str
>>> str \'' str
>>>
>>> str \'\' str
>>> str \'\' str
>>>
>>> 'str'
>>> \'str\'
>>>
>>> \'str\'
>>> \'str\'
>>>
>>>
>>> Martin Scotta
>>
>> --
>> PHP Internals - PHP Runtime Development Mailing List
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> Did no one see why the regex was wrong?
>
> RegexBuddy (a windows app) explains regexes VERY VERY well.
The important bit (where the problem lies with regard to the regex) is ...
Match a single character NOT present in the list below «[^\\\\]»
A \ character «\\»
A \ character «\\»
The issue is the word _single_.
--
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php