A regular expression is a sequence of characters that forms a search pattern. When you search for data in a text, you can use this search pattern to describe what you are looking for.
PHP provides several functions that allow you to use regular expressions. The most common ones are:
preg_match() - Returns 1 if the pattern was found in the string and 0 if not.preg_match_all() - Returns how many times the pattern was found in the string.preg_replace() - Returns a new string where matched patterns have been replaced with new text.The preg_match() function tells you whether a string contains matches of a pattern.
Modifiers can change how a search is performed. Common modifiers include:
i - Performs a case-insensitive search.m - Performs a multi-line search.u - Enables correct matching of UTF-8 encoded characters.The preg_replace() function replaces all matches of a pattern in a string with another string.
Meta-characters are characters with a special meaning:
[abc] - Find any character between the brackets.[^abc] - Find any character NOT between the brackets.[0-9] - Find any character from 0 to 9./ at the start and end of the pattern are called delimiters. They tell PHP where the expression starts and ends.