note 115599 added to function.preg-match

From: Date: Fri, 22 Aug 2014 13:27:23 +0000
Subject: note 115599 added to function.preg-match
Groups: php.notes php.notes 
Request: Send a blank email to php-notes+get-200289@lists.php.net to get a copy of this message
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 ) ---- Server IP: 72.52.91.14 Probable Submitter: 83.114.109.109 ---- Manual Page -- http://php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/115599 Del: integrated -- https://master.php.net/note/delete/115599/integrated Del: useless -- https://master.php.net/note/delete/115599/useless Del: bad code -- https://master.php.net/note/delete/115599/bad+code Del: spam -- https://master.php.net/note/delete/115599/spam Del: non-english -- https://master.php.net/note/delete/115599/non-english Del: in docs -- https://master.php.net/note/delete/115599/in+docs Del: other reasons-- https://master.php.net/note/delete/115599 Reject -- https://master.php.net/note/reject/115599 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#200289) next »