diff --git "a/include/class-regex\\Generic.php" "b/include/class-regex\\Generic.php" index c75da39..1a15f57 100644 --- "a/include/class-regex\\Generic.php" +++ "b/include/class-regex\\Generic.php" @@ -1,122 +1,122 @@ . namespace regex; /** * Handle generic regexes */ class Generic { /** * Create a regex with the first character insensitive * * @param $s string * @param $group_name string|null * @return string */ public static function firstCaseInsensitive( $s, $group_name = null ) { list( $fc, $rest ) = self::splitFirstCase( $s ); return self::groupNamed( self::insensitiveChar( $fc ), $group_name ) . $rest; } /** * Match a case insensitive string * * @param $s string * @return string */ public static function insensitive( $s ) { $s = preg_quote( $s ); return "(?i)$s(?-i)"; } /** * Create a regex with a capturing group with a name * * @param $group string * @param $name string Name or NULL to do not group * @return string */ public static function groupNamed( $group, $name = null ) { if( null === $name ) { return $group; } return "(?P<$name>$group)"; } /** * Get a group name usable as replacement e.g. in preg_replace() * * @param $name string * @return string */ public static function groupName( $name ) { return '${' . $name . '}'; } public static function spaceBurger( $s ) { - return self::burger( $s, '[_ ]*' ); + return self::burger( $s, '[ _]*' ); } public static function tabBurger( $s ) { return self::burger( $s, '[ \t]*' ); } public static function newlineBurger( $s ) { return self::burger( $s, '[ \t\n]*' ); } /** * Take a character and get a case insensitive regex * * @param $c string * @return string */ private static function insensitiveChar( $c ) { $u = strtoupper( $c ); $l = strtolower( $c ); if( $u === $l ) { return $c; } return "[$u$l]"; } /** * Split the string into an array with the first char and the rest * * @param $s string * @return array */ private static function splitFirstCase( $s ) { return [ substr( $s, 0, 1 ), substr( $s, 1 ) ]; } /** * Surround the string with something before and after * * @param $s string * @param $bread string * @return string */ public static function burger( $s, $bread ) { return $bread . $s . $bread; } }