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 with zero or more occurrences?
- How to remove all non-numeric characters using PHP regex?
- How to convert a PHP regex to JavaScript regex?
- How to format a phone number using regex in PHP?
- How to use PHP regex to match a year?
- How to use PHP regex to match an exact string?
- How to use PHP regex to match special characters?
- How to use PHP regex to match a zip code?
- How to use PHP regex with the "x" modifier?
See more codes...