[php-src] Issue #7950: preg_match fails to match zero
| From: | Adam2Marsh | Date: | Sat, 15 Jan 2022 23:39:40 +0000 |
| Subject: | [php-src] Issue #7950: preg_match fails to match zero | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-239029@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/7950
Author: Adam2Marsh
### Description
The following code:
```php
<?php
$value=0.0;
preg_match("/(\d+)\.(\d+)/",$value, $matches);
print_r($matches);
```
Resulted in this output:
```
Array
(
)
```
But I expected this output instead:
```
Array
(
[0] => 0.0
[1] => 0
[2] => 0
)
```
I found this as in my code I need to strip the numbers off the decimal point, now sometimes that
decimal point might just be a 0 and my regex failed to match. As soon as I change the last number to
be any number then it works. The first number can be anything, that doesn't matter. I even
tried the following regex patterns and still wouldn't match
```
"/\d+\.(\d+)&/"
"/\.(\d+)/"
"/\.(\d+)&/"
```
Php Version:
```
php -v
PHP 8.1.1 (cli) (built: Jan 9 2022 20:13:47) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.1, Copyright (c) Zend Technologies
with Zend OPcache v8.1.1, Copyright (c), by Zend Technologie
```
Running on osx m1 Mac, any ideas?
### PHP Version
8.1.1
### Operating System
m1 osx 12.0.1