Created
October 25, 2010 08:14
-
-
Save aerith/644591 to your computer and use it in GitHub Desktop.
文字列が正規表現パターンかどうかをそれっぽく判別する関数。
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 | |
/* | |
* 文字列が正規表現パターンかどうかをそれっぽく判別する関数。 | |
*/ | |
function regexpUses($pattern) | |
{ | |
// See: http://php.net/manual/reference.pcre.pattern.modifiers.php | |
// See: http://php.net/manual/regexp.reference.delimiters.php | |
if (preg_match('@^([^\s\\\\a-z0-9])(?:.*?)\1(?:[imsxeADSUXJu]*)?$@mD', $pattern)) return true; | |
if (preg_match('@^\{(?:.*?)\}(?:[imsxeADSUXJu]*)?$@mD', $pattern)) return true; | |
if (preg_match('@^\[(?:.*?)\](?:[imsxeADSUXJu]*)?$@mD', $pattern)) return true; | |
if (preg_match('@^\<(?:.*?)\>(?:[imsxeADSUXJu]*)?$@mD', $pattern)) return true; | |
if (preg_match('@^\((?:.*?)\)(?:[imsxeADSUXJu]*)?$@mD', $pattern)) return true; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment