Explain what this PHP regular expression means (preg_match_all)

php, regex

Solution

This pattern `'#^/abc/(?P<abc>[^/]++)$#si';` broken down like so:

/^\/abc\/(?P<abc>[^\/]++)$/si

^ assert position at start of the string
\/ matches the character / literally
abc matches the characters abc literally (case insensitive)
\/ matches the character / literally
(?P<abc>[^\/]++) Named capturing group abc
    [^\/]++ match a single character not present in the list below
        Quantifier: Between one and unlimited times, as many times as possible, without giving back [possessive]
        \/ matches the character / literally
$ assert position at end of the string
s modifier: single line. Dot matches newline characters
i modifier: insensitive. Case insensitive match (ignores case of [a-zA-Z])

(Source: http://regex101.com/r/hS6qE3 -- make sure you escape your `/` on the site as it assumes `/` is the php delimiter. In your pattern example, `#` is the delimiter instead, which is then wrapped in quotes and the string terminator `;`. The actual expression is simply `^/abc/(?P<abc>[^/]++)$` with the single-line and case insensitive modifiers.)

Note the use of two `++` signs as well, which changes the behavior from greedy to possessive.

An example of a string that will match:

/abc/somethingelsenotafrontslash

You can read a quick explanation about `preg_match_all` `here`

Problem

What is pattern mean in PHP: `'#^/abc/(?P<abc>[^/]++)$#si'; // please expand this pattern's meaning.` and what are strings can match of this pattern with `preg_match_all`?

Original source

Related problems