模板的正则表达式日期格式无效

I'm trying to replace variables like {{{month}}} in a template to the current month and {{{month+1}}} to current month + 1. That's not the hardest part of my code, except that the regex I wrote doesn't yield expected results.

$string = '{{{year}}}{{{month+1}}}';
preg_match_all('/{{{(?:([yY])ear|([mM])onth|([dD])ay)(?:(?<operation>[-|+])(?<amount>[1-9]+))?}}}/m', $string, $matches);
var_dump($matches);

Why do I have so much empty array entries? I was expecting

[0] => array('{{{year}}}', '{{{month+1}}}')
[1] => array('y', 'm')
[2] => array('', '+')
[3] => array('', '1')

What am I doing wrong?

The respond of the above code is:

array(8) {
  [0]=>
  array(2) {
    [0]=>
    string(10) "{{{year}}}"
    [1]=>
    string(13) "{{{month+1}}}"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "y"
    [1]=>
    string(0) ""
  }
  [2]=>
  array(2) {
    [0]=>
    string(0) ""
    [1]=>
    string(1) "m"
  }
  [3]=>
  array(2) {
    [0]=>
    string(0) ""
    [1]=>
    string(0) ""
  }
  ["operation"]=>
  array(2) {
    [0]=>
    string(0) ""
    [1]=>
    string(1) "+"
  }
  [4]=>
  array(2) {
    [0]=>
    string(0) ""
    [1]=>
    string(1) "+"
  }
  ["amount"]=>
  array(2) {
    [0]=>
    string(0) ""
    [1]=>
    string(1) "1"
  }
  [5]=>
  array(2) {
    [0]=>
    string(0) ""
    [1]=>
    string(1) "1"
  }
}

You may use a "generic" character class to match the first letters of month, year and day, and then use an alternation with positive look-behinds to make sure we match what we need.

preg_match_all('/{{{([yYmMdD])(?:(?<=[Yy])ear|(?<=[Mm])onth|(?<=[Dd])ay)(?:([-‌​+])([1-9]+))?}}}/m', $string, $matches);

See IDEONE demo

And this is the print_r view:

Array
(
    [0] => Array
        (
            [0] => {{{year}}}
            [1] => {{{month+1}}}
        )

    [1] => Array
        (
            [0] => y
            [1] => m
        )

    [2] => Array
        (
            [0] => 
            [1] => +
        )

    [3] => Array
        (
            [0] => 
            [1] => 1
        )

)