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
imodifier: 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 UUID?
- How to use PHP regex to match a word?
- How to use PHP regex to match special characters?
- How to use PHP regex to match an exact string?
- How to use PHP regex to match URL path?
- How to use PHP regex to match time?
- How to remove non-printable characters using PHP regex?
- How to use the "s" modifier in PHP regex?
- How to use PHP regex to match UTF8?
See more codes...