Voting

: zero minus zero?
(Example: nine)

The Note You're Voting On

qdinar at gmail dot com
7 years ago
when regex is for longer and shorter version of a string,
only one of that long and short versions is catched.
when regex match occurs in one position of string,
only one match is saved in matches[0] for that position.
if ? is used, regex is greedy, and catches more long version,
if | is used, most first matching variant is catched:
<?php
preg_match_all
('/ab|abc/','abc',$m);
var_dump($m);
preg_match_all('/abc?/','abc',$m);
var_dump($m);
?>
['ab', 'abc'] in $m[0] for both can be expected, but it is not so,
actually they output [['ab']] and [['abc']]:
array(1) {
[0]=>
array(1) {
[0]=>
string(2) "ab"
}
}
array(1) {
[0]=>
array(1) {
[0]=>
string(3) "abc"
}
}

<< Back to user notes page

To Top