PHP theorytheory 0/50 · 0%
Strings · medium

34. Regular Expressions

Pattern matching with PCRE.

PHP's regex functions (preg_match, preg_match_all, preg_replace, preg_split) use the PCRE engine and require patterns delimited by a character such as /pattern/flags. preg_match() returns 1 if a match is found and can populate a matches array via reference.

preg_replace_callback() is preferred over preg_replace() with the /e modifier (removed in PHP 7) when replacement logic needs to run code rather than a static string.

Check your understanding

  1. 1. Which function tests whether a string matches a pattern and captures groups?

  2. 2. What must delimit a PCRE pattern string in PHP?