Ignoring Case in Regex in PHP
By default, in regex, the case of characters matters. In the following example, we will find only lowercase letters:
<?php
preg_replace('#[a-z]+#', '!', 'aaa bbb AAA'); // returns '! ! AAA'
?>
We can change this regex behavior
by using the modifier i. Let's correct
our regex accordingly:
<?php
preg_replace('#[a-z]+#i', '!', 'aaa bbb AAA'); // returns '! ! !'
?>
Simplify the following code by using the appropriate modifier:
<?php
preg_replace('#[a-zA-Z]+#', '!', 'aaa BBB');
?>