Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.