I’m using PHP 8.2.11 on Mac Sonoma 14.5.
My code is:
$cost = '£45.56–34.90';
$matches = array();
$found = preg_match(
'/£?.*£?/',
$cost,
$matches
);
I’d expect preg_match()
to return 1
, indicating a match, and to populate $matches
like this:
array (
0 => '£45.56–34.90',
)
However, $found === 0
and $matches
is empty.
I tested this on https://regex101.com, which matched as I expected.
If I change my code so that $cost === '£45.56–£34.90'
(with a second pound sign added), then $found === 1
and $matches
is populated as:
array (
0 => '£45.56–£34.90',
)
If I change my code so that $cost === '£45.56–34.90'
and the pattern is '/£?.*£?/g'
, then $found === false
.
New contributor