I suggest we use a simpler and faster way like in Yii2: https://github.com/yiisoft/yii2/blob/master/framework/web/UrlRule.php#L156