Created
October 24, 2008 00:35
-
-
Save speedmax/19293 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 strip_regex($regex, $delimiter = '/') { | |
return substr($regex, 1, strrpos($regex, $delimiter)-1); | |
} | |
class H2O_RE { | |
static $whitespace, $seperator, $parentheses, $pipe, $name, $filter_end, | |
$string, $i18n_string, $number, $operator, $named_args; | |
function init() { | |
$_ = 'strip_regex'; | |
self::$whitespace = '/\s+/m'; | |
self::$parentheses = '/\(|\)/m'; | |
self::$seperator = '/,/'; | |
self::$pipe = '/\|/'; | |
self::$name = '/[a-zA-Z][a-zA-Z0-9-_]*(?:\.[a-zA-Z_0-9][a-zA-Z0-9_-]*)*/'; | |
self::$filter_end = '/;/'; | |
self::$string = '/(?: | |
"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)" | \'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\' # Single Quote String | |
)/xsm'; | |
self::$i18n_string = "/_\({$_(self::$string)}\)/xsm"; | |
self::$number = '/\d+(\.\d*)?/'; | |
self::$operator = '/\s?(>|<|=|>=|<=|!=|==|and|not|or)\s/i'; | |
self::$named_args = "{ | |
({$_(self::$name)}) {$_(self::$whitespace)}?: {$_(self::$whitespace)}? ({$_(self::$i18n_string)} | {$_(self::$string)} | {$_(self::$number)} | {$_(self::$name)}) | |
}x"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment