Skip to content

Instantly share code, notes, and snippets.

@m8rge m8rge/AsteriskMatch.php
Last active Jan 29, 2016

What would you like to do?
Test string against simple mask with asterisk *
class AsteriskMatch
* @param string $mask string with asterisk
* @param string $string tested subject
* @return bool
* @throws \Exception
public static function match($mask, $string)
$regex = str_replace('\\*', '.*', preg_quote($mask, '/'));
$match = preg_match("/^$regex$/u", $string);
if (is_int($match)) {
return (bool)$match;
} else {
throw new \Exception('Preg error: ' . preg_last_error());
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.