Skip to content

Instantly share code, notes, and snippets.

@magnetikonline
Created March 28, 2014 03:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnetikonline/9824748 to your computer and use it in GitHub Desktop.
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.
<?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