php-regexHow to use regex flags in PHP?
Regex flags are used to modify the behavior of a regular expression in PHP.
The most commonly used flags are i for case-insensitive matching, m for multiline matching, and s for dotall mode.
Example code
$pattern = '/^[a-z]$/i';
$string = 'A';
if (preg_match($pattern, $string)) {
echo 'Match found';
}
Output example
Match found
Code explanation
$pattern: The regular expression pattern to be used for matching.$string: The string to be matched against the pattern.preg_match(): The function used to match the string against the pattern./i: The regex flag used to make the pattern case-insensitive.
Helpful links
More of Php Regex
- How to use PHP regex to match a zip code?
- How to use PHP regex to match a year?
- How to use PHP regex to match URL path?
- How to use PHP regex to match time?
- How to remove all non-numeric characters using PHP regex?
- How to remove non-printable characters using PHP regex?
- How to use PHP regex to match a line break?
- How to use PHP regex in a case insensitive mode?
- How to use PHP regex to match a hashtag?
- How to use PHP regex with zero or more occurrences?
See more codes...