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 nbsp HTML whitespace?
- How to use an "or" condition in PHP regex?
- How to use PHP regex to get a YouTube video ID?
- How to match a space using PHP regex?
- How to use PHP regex to match a zip code?
- How to use PHP regex to match an exact string?
- How to use PHP regex to match special characters?
- How to use PHP regex with the "x" modifier?
- How to use PHP regex to match whitespace?
- How to use PHP regex to match a year?
See more codes...