Edit report at https://bugs.php.net/bug.php?id=64145&edit=1

 ID:                 64145
 Updated by:         krak...@php.net
 Reported by:        mrsnikivan at gmail dot com
 Summary:            preg_match return false for using (\$)
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            PCRE related
 Operating System:   window
 PHP Version:        5.3.21
 Block user comment: N
 Private report:     N

 New Comment:

The pattern you gave is never going to match the token provided, [A-Ia-i] will 
never match sum; I assume the token has been provided incorrect:

<?php
$token='$a1:$a1';
var_dump(preg_match("/^(\\$)?[A-Ia-i]?[A-Za-z](\\$)?[0-9]+:(\\$)?[A-Ia-i]?[A-Za-
z](\\$)?[0-9]+$/",$token, $matches));
print_r($matches);
?>

You need to escape $ twice when using double quotes.

<?php
$token='$a1:$a1';
var_dump(preg_match('/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z]
(\$)?[0-9]+$/',$token, $matches));
print_r($matches);
?>

Both examples function as expected.


Previous Comments:
------------------------------------------------------------------------
[2013-02-04 19:30:36] mrsnikivan at gmail dot com

Description:
------------
I using worksheet de pear(library parse.php, found problem for preg_match)

$token='=sum($a1:$a1);
if 
(preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token))
 {
...
}
no true
$token='=sum(a1:a1);
if 
(preg_match("/^(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+:(\$)?[A-Ia-i]?[A-Za-z](\$)?[0-9]+$/",$token))
 {
...
}
is true

Test script:
---------------
$ change another different character and no problem sample @

$token='=sum(@a1:@a1);
if 
(preg_match("/^(\@)?[A-Ia-i]?[A-Za-z](\@)?[0-9]+:(\@)?[A-Ia-i]?[A-Za-z](\@)?[0-9]+$/",$token))
 {
...
}

After trying other caracters I found that the problem is that the $ replace 
internal a point (.) character 46

$token='=sum($a1:$a1);
if 
(preg_match("/^(.)?[A-Ia-i]?[A-Za-z](.)?[0-9]+:(.)?[A-Ia-i]?[A-Za-z](.)?[0-9]+$/",$token))
 {
...
}
here if there was affirmative result for dollar ($) and point (.)



Expected result:
----------------
true for (\$) for preg_match

Actual result:
--------------
false for (\$) for preg_match


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64145&edit=1

Reply via email to