PHP Regular Expression Functions and Symbols

PHP Output Functions
PHP Stream Functions

Regular Expression functions allow you to search specific patterns in the string and replace them with some other pattern/string.

On this page, you will find the regular expression functions, their relative information like special characters/symbols, and their meanings.

FunctionDescription
preg_filter()Get string or array with pattern matches replaced, but only if matches were found
preg_grep()Get an array of elements from the input array which matched the pattern
preg_last_error()Get an error code showing the reason that the last regular expression call failed
preg_match()Get the first match of a pattern in a string
preg_match_all()Get all matches of a pattern in a string
preg_replace()Get strings were matches of a pattern replaced with a substring. The substring value is returned by the callback function.
preg_replace_callback()Get string where all matches of the expression are replaced with the substring. The substring value is returned by the callback function.
preg_replace_callback_array()Get a string where all matches of each expression are replaced with the substring. The substring value is returned by the callback function.
preg_split()Break the string based on the regular expressions and return the partitions of the string as array
preg_quote()Put a backslash in front of characters that have a special meaning in regular expressions
PHP Regex Functions

Modifiers in Regex

Modifiers define the behavior of searching for patterns in the string.

ModifierDescription
icase-insensitive search for the pattern
mSearch in multiline. That is, search for a matching pattern at the beginning or end of each line
uEnables correct matching of UTF-8 encoded patterns
Expression Modifiers

Regex Patterns

Brackets define the range of characters to create patterns.

[abc]Find a character from the items between the brackets
[^abc]Find character NOT between the brackets
[0-9]Find a character from 0 to 9
Regular Expression Patterns

Regex Metacharacters

Metacharacters are characters with a special meaning:

MetacharacterDescription
|Look for a match for any one of the patterns separated by |
.Look for one instance of any character
^Look for a match as the beginning of a string
$Find match at the end of the string
\dFind a digit
\sFind a whitespace character
\bFind a match at the beginning of a word
\uxxxxFind the Unicode character given by the hexadecimal number XXXX
Metacharacters in PHP regex

Quantifiers in Regex

Quantities are defined by quantifiers.

QuantifierDescription
n+Find string containing at least one n
n* Find string containing zero or more occurrences of n
n? Find string containing zero or one occurrence of n
n{x} Find string containing sequence of X n‘s
n{x,y} Find string containing sequence of X to Y n‘s
n{x,} Find string containing sequence of at least X n‘s
Quantifiers

PHP Output Functions
PHP Stream Functions
en English
X
Scroll to Top