Created
March 28, 2014 03:33
-
-
Save magnetikonline/9824748 to your computer and use it in GitHub Desktop.
Enabling PHP PCRE case insensitive searching for specific sections of your regular expression.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$testExpression = '/(?i)te(?-i)st/'; | |
testPCRESectionOnly($testExpression,'test'); | |
testPCRESectionOnly($testExpression,'TEst'); | |
testPCRESectionOnly($testExpression,'teST'); | |
testPCRESectionOnly($testExpression,'TEST'); | |
/* | |
Should return: | |
Match | |
Match | |
No match | |
No match | |
More information here: http://www.regular-expressions.info/modifiers.html | |
*/ | |
function testPCRESectionOnly($regExp,$testString) { | |
if (preg_match($regExp,$testString)) { | |
echo("Match\n"); | |
return; | |
} | |
echo("No match\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment