note 115599 deleted from function.preg-match by cmb

From: Date: Sun, 13 Oct 2019 07:52:46 +0000
Subject: note 115599 deleted from function.preg-match by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212615@lists.php.net to get a copy of this message
Note Submitter: Gilles A ---- Using named subpattern : Since PCRE 7.0 ( PHP >= 5.2.2) , named groups can be defined using (?<name>) or (?'name') instead of (?P<name>) <?php $str = 'foobar: 2008'; preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches); print_r($matches); //Or preg_match('/(?\'name\'\w+): (?\'digit\'\d+)/', $str, $matches); print_r($matches); //Or preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches); print_r($matches); ?> //Result Array ( [0] =>foobar: 2008 [name] => foobar [1] => foobar [digit] => 2008 [2] => 2008 ) Array ( [0] => foobar: 2008 [name] => foobar [1] => foobar [digit] => 2008 [2] => 2008 ) Array ( [0] => foobar: 2008 [name] => foobar [1] => foobar [digit] => 2008 [2] => 2008 )

« previous php.notes (#212615) next »