regexp [message #173491] |
Fri, 15 April 2011 19:51 |
smerf
Messages: 12 Registered: January 2011
Karma: 0
|
Junior Member |
|
|
["regexp"]=>
string(93) "^/(?Particles|admin/comments|blog)(/(?P[^/]+?)?(/(?P[^/]+?)?)?)?(/)?$"
What is making "?P" above ?
|
|
|
Re: regexp [message #173493 is a reply to message #173491] |
Fri, 15 April 2011 19:59 |
Luuk
Messages: 329 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 15-04-2011 21:51, smerf wrote:
> ["regexp"]=>
> string(93)
> "^/(?Particles|admin/comments|blog)(/(?P[^/]+?)?(/(?P[^/]+?)?)?)?(/)?$"
>
> What is making "?P" above ?
no sure
but maybe this page gives answers?:
http://www.php.net/manual/en/regexp.reference.meta.php
?
extends the meaning of (, also 0 or 1 quantifier, also makes greedy
quantifiers lazy (see repetition)
--
Luuk
|
|
|
Re: regexp [message #173496 is a reply to message #173491] |
Fri, 15 April 2011 21:21 |
Michael Fesser
Messages: 215 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
.oO(smerf)
> ["regexp"]=>
> string(93) "^/(?Particles|admin/comments|blog)(/(?P[^/]+?)?(/(?P[^/]+?)?)?)?(/)?$"
>
> What is making "?P" above ?
Usually ?P is used to give a name to a subpattern, e.g.
(?P<foo>.*)
This match can then be accessed by the name 'foo' in the result set. But
in the above example there are no names given, so I'm not sure what the
?Ps are supposed to do there.
Micha
|
|
|
Re: regexp [message #173507 is a reply to message #173496] |
Sat, 16 April 2011 08:08 |
Luuk
Messages: 329 Registered: September 2010
Karma: 0
|
Senior Member |
|
|
On 15-04-2011 23:21, Michael Fesser wrote:
> .oO(smerf)
>
>> ["regexp"]=>
>> string(93) "^/(?Particles|admin/comments|blog)(/(?P[^/]+?)?(/(?P[^/]+?)?)?)?(/)?$"
>>
>> What is making "?P" above ?
>
> Usually ?P is used to give a name to a subpattern, e.g.
>
> (?P<foo>.*)
>
> This match can then be accessed by the name 'foo' in the result set. But
> in the above example there are no names given, so I'm not sure what the
> ?Ps are supposed to do there.
>
> Micha
hm i learned something today ;)
http://www.php.net/manual/en/regexp.reference.subpatterns.php
"It is possible to name a subpattern using the syntax (?P<name>pattern).
This subpattern will then be indexed in the matches array by its normal
numeric position and also by name. PHP 5.2.2 introduced two alternative
syntaxes (?<name>pattern) and (?'name'pattern)."
Too bad that some simple example are missing for this 'complex'stuff.... ;)
--
Luuk
|
|
|