note 89418 added to function.preg-match
| From: | daevid at daevid dot com | Date: | Fri, 06 Mar 2009 23:18:44 +0000 |
| Subject: | note 89418 added to function.preg-match | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-151574@lists.php.net to get a copy of this message | ||
I just learned about named groups from a Python friend today and was curious if PHP supported them,
guess what -- it does!!!
http://www.regular-expressions.info/named.html
<?php
preg_match("/(?P<foo>abc)(.*)(?P<bar>xyz)/",
'abcdefghijklmnopqrstuvwxyz',
$matches);
print_r($matches);
?>
will produce:
Array
(
[0] => abcdefghijklmnopqrstuvwxyz
[foo] => abc
[1] => abc
[2] => defghijklmnopqrstuvw
[bar] => xyz
[3] => xyz
)
Note that you actually get the named group as well as the numerical key
value too, so if you do use them, and you're counting array elements, be
aware that your array might be bigger than you initially expect it to be.
----
Server IP: 208.69.120.35
Probable Submitter: 206.169.197.253
----
Manual Page -- http://www.php.net/manual/en/function.preg-match.php
Edit -- https://master.php.net/note/edit/89418
Del: integrated -- https://master.php.net/note/delete/89418/integrated
Del: useless -- https://master.php.net/note/delete/89418/useless
Del: bad code -- https://master.php.net/note/delete/89418/bad+code
Del: spam -- https://master.php.net/note/delete/89418/spam
Del: non-english -- https://master.php.net/note/delete/89418/non-english
Del: in docs -- https://master.php.net/note/delete/89418/in+docs
Del: other reasons-- https://master.php.net/note/delete/89418
Reject -- https://master.php.net/note/reject/89418
Search -- https://master.php.net/manage/user-notes.php