php-regexHow to use PHP regex in a case insensitive mode?
To use PHP regex in a case insensitive mode, you can use the i
modifier. This modifier will make the regex match case insensitively.
For example:
$string = 'Hello World';
$pattern = '/hello/i';
if (preg_match($pattern, $string)) {
echo 'Match found';
}
Output example
Match found
The i
modifier can be used with any regex pattern. It is placed after the closing /
of the pattern.
Code explanation
i
modifier: This modifier makes the regex match case insensitively.preg_match()
: This function is used to match a regex pattern against a string.
Helpful links
More of Php Regex
- How to use PHP regex to match a nbsp HTML whitespace?
- How to use PHP regex to match a zip code?
- How to use PHP regex with zero or more occurrences?
- How to use PHP regex to get a YouTube video ID?
- How to use PHP regex with the "x" modifier?
- How to use PHP regex to match an exact string?
- How to use PHP regex to match UUID?
- How to match a space using PHP regex?
- How to use quantifiers in PHP regex?
- How to match the end of a string when using regex in PHP?
See more codes...