Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6994
| From | Scott Johnson <noonehome@chalupasworld.com> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Dynamic backreferences, finding last in a group |
| Date | 2012-09-09 07:16 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <k2i8cd$ecm$1@dont-email.me> (permalink) |
| References | <7ebf5417-2d22-4585-b50a-ba661025ae36@googlegroups.com> <87bohffm75.fsf@huddi.jernurt.dk> |
On 9/9/2012 4:51 AM, Anders Wegge Keller wrote:
> Jason C <jwcarlton@gmail.com> writes:
>
>> Any suggestions?
>
> Read the manual on regexp syntax, and use named patterns.
>
Wow that is a very good feature I never know about.
This I can imagine will come in very handy.
Thanks
Scotty
Example #4 Using named subpattern
<?php
$str = 'foobar: 2008';
preg_match('/(?P<name>\w+): (?P<digit>\d+)/', $str, $matches);
/* This also works in PHP 5.2.2 (PCRE 7.0) and later, however
* the above form is recommended for backwards compatibility */
// preg_match('/(?<name>\w+): (?<digit>\d+)/', $str, $matches);
print_r($matches);
?>
The above example will output:
Array
(
[0] => foobar: 2008
[name] => foobar
[1] => foobar
[digit] => 2008
[2] => 2008
)
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
Dynamic backreferences, finding last in a group Jason C <jwcarlton@gmail.com> - 2012-09-09 03:31 -0700
Re: Dynamic backreferences, finding last in a group Anders Wegge Keller <wegge@wegge.dk> - 2012-09-09 13:51 +0200
Re: Dynamic backreferences, finding last in a group Scott Johnson <noonehome@chalupasworld.com> - 2012-09-09 07:16 -0700
csiph-web