U
U
ubuntu_lts2020-07-05 21:49:39
PHP
ubuntu_lts, 2020-07-05 21:49:39

Is it necessary to denote the parameter with the letter P in regex?

I’m sawing a router alone, well, so to speak, by accident in the regular season I forgot to add the parameter designation with the letter P, that is, according to the classics, it should be like this:

Router::addRule('^(?P<controller>[a-z-]+)/?(?P<action>[a-z-]+)?$');

and i wrote it like this
Router::addRule('^(?<controller>[a-z-]+)/?(?<action>[a-z-]+)?$');

I notice that it works this way and that, is it necessary to designate the parameters with the letter P?
Actually such here and a question.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-sem, 2020-07-05
@ubuntu_lts

PHP 5.2.2 added two alternative named group syntaxes to make it easier for programmers from other languages. https://www.php.net/manual/en/regexp.reference.sub...
So, if you don't do necromancy, then there is no difference.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question