public function match($url) { /* Unfinished shit */ $url = trim($url, '/'); $regex = Regex::of('#:([\\w]+)#'); $path = $regex->with($this->path)->replaceWithCallback(function (Regex $self) { return '([^/]+)'; }); $reg = Regex::of("#^" . $path . "\$#i"); foreach ($reg->with($url) as $match) { var_dump($match); } return false; }
public static function LandingLoadWidgetMessageEvent(User $user, PacketParser $packet, ClassContainer $util) { $widget = $packet->readString(); $response = new PacketConstructor(); $response->SetHeader($util->HeaderManager->Outgoing("LandingWidgetMessageComposer")); if (isset($widget) && $widget != "") { $eventData = explode(",", $widget); if (Regex::match("/gamesmaker/i", $eventData[1])) { return; } $response->WriteString($widget); $response->WriteString($eventData[1]); } else { $response->WriteString(""); $response->WriteString(""); } $user->Send($response->Finalize()); }
--TEST-- Basic regex test - object.replace (+first) --FILE-- <?php use php\util\Regex; use php\util\RegexException; $regex = Regex::of('([0-9]+)'); var_dump($regex->with('1 2 3')->replace('|$1|')); var_dump($regex->with('1 2 3')->replaceFirst('|$1|')); $tmp = $regex->with('1 2 3'); var_dump($tmp->replaceWithCallback(function (Regex $r) use($tmp) { if ($tmp !== $r) { throw new Exception(); } return '|$1|'; })); ?> --EXPECT-- string(11) "|1| |2| |3|" string(7) "|1| 2 3" string(11) "|1| |2| |3|"
--TEST-- Basic regex test - object.matches --FILE-- <?php use php\util\Regex; use php\util\RegexException; $regex = Regex::of('[0-9]+'); var_dump($regex->with('100500')->matches()); var_dump($regex->with(' 100500 ')->matches()); var_dump($regex->with('a100500')->matches()); ?> --EXPECT-- bool(true) bool(false) bool(false)
--TEST-- Basic regex test - match --FILE-- <?php use php\lang\IllegalArgumentException; use php\util\Regex; echo "Regex::match('^[0-9]+\$', '03894') == ", Regex::match('^[0-9]+$', '03894') ? "1" : "0", "\n"; echo "Regex::match('^[0-9]+\$', ' 03894') == ", Regex::match('^[0-9]+$', ' 03894') ? "1" : "0", "\n"; echo "--text-invalid\n"; try { echo "Regex::match('^[0-9+\$', '333') == ", Regex::match('^[0-9+$', '333'); } catch (IllegalArgumentException $e) { echo "test success exception\n"; } var_dump(Regex::match('sss', ' SSs ', Regex::CASE_INSENSITIVE)); var_dump(Regex::match('sss', ' SSs ')); var_dump(Regex::match('sss', ' sss ')); var_dump(Regex::match('^sss$', ' sss ')); var_dump(Regex::match('^sss$', 'sss')); ?> --EXPECT-- Regex::match('^[0-9]+$', '03894') == 1 Regex::match('^[0-9]+$', ' 03894') == 0 --text-invalid Regex::match('^[0-9+$', '333') == test success exception bool(true) bool(false) bool(true) bool(false) bool(true)
--TEST-- Basic regex test - quote --FILE-- <?php use php\util\Regex; var_dump(Regex::quote('^foobar$')); var_dump(Regex::quoteReplacement('$1')); ?> --EXPECT-- string(12) "\Q^foobar$\E" string(3) "\$1"
--TEST-- Basic regex test - match --FILE-- <?php use php\lang\IllegalArgumentException; use php\util\Regex; echo "Regex::match('^[0-9]+\$', '03894') == ", Regex::match('^[0-9]+$', '03894') ? "1" : "0", "\n"; echo "Regex::match('^[0-9]+\$', ' 03894') == ", Regex::match('^[0-9]+$', ' 03894') ? "1" : "0", "\n"; echo "--text-invalid\n"; try { echo "Regex::match('^[0-9+\$', '333') == ", Regex::match('^[0-9+$', '333'); } catch (IllegalArgumentException $e) { echo "test success exception"; } ?> --EXPECT-- Regex::match('^[0-9]+$', '03894') == 1 Regex::match('^[0-9]+$', ' 03894') == 0 --text-invalid Regex::match('^[0-9+$', '333') == test success exception
--TEST-- Basic regex test - split --FILE-- <?php use php\lang\IllegalArgumentException; use php\util\Regex; var_dump(Regex::split('[0-9]+', 'foo93894bar840')); try { echo "--test-invalid\n"; Regex::split('[0-9+', '389foo93894bar840'); } catch (IllegalArgumentException $e) { echo "test success exception"; } ?> --EXPECT-- array(2) { [0]=> string(3) "foo" [1]=> string(3) "bar" } --test-invalid test success exception
--TEST-- Basic regex test - object.reset --FILE-- <?php use php\util\Regex; $regex = Regex::of('[0-9]+')->with('1 2 3'); var_dump($regex->matches()); $regex->reset('123'); var_dump($regex->matches()); ?> --EXPECT-- bool(false) bool(true)