XXXIX. PCRE functions

These functions are intended for work with Perl Compatible Regular Expressions.

The syntax for patterns used in these functions closely resembles Perl. The expression should be enclosed in the delimiters, a forward slash (/), for example. Any character can be used for delimiter as long as it's not alphanumeric or backslash (\). If the delimiter character has to be used in the expression itself, it needs to be escaped by backslash.

The ending delimiter may be followed by various options that affect the matching. See Pattern Options.

Example 1. Examples of valid patterns

  • /<\/\w+>/

  • |(\d{3})-\d+|Sm

  • /^(?i)php[34]/

Example 2. Examples of invalid patterns

  • /href='(.*)' - missing ending delimiter

  • /\w+\s*\w+/J - unknown option 'J'

  • 1-\d3-\d3-\d4| - missing starting delimiter

Table of Contents
preg_match — Perform a regular expression match
preg_match_all — Perform a global regular expression match
preg_replace — Perform a regular expression search and replace
preg_split — Split string by a regular expression
Pattern Options — describes possible options in regex patterns