php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64145 preg_match return false for using (\$)
Submitted: 2013-02-04 19:30 UTC Modified: 2013-02-04 19:50 UTC
From: mrsnikivan at gmail dot com Assigned:
Status: Not a bug Package: PCRE related
PHP Version: 5.3.21 OS: window
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: mrsnikivan at gmail dot com
New email:
PHP Version: OS:

 

 [2013-02-04 19:30 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-02-04 19:50 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2013-02-04 19:50 UTC] krakjoe@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 04:01:32 2024 UTC