Problem capturing string type with Altorouter router

Asked

Viewed 31 times

2

I’m using Altorouter to make the page call of my project, and in his doc says that to use "Match Types" custom just add

$router->addMatchTypes(array('cId' => '[a-zA-Z]{2}[0-9](?:_[0-9]++)?'));

However, I tried using this rule: |^[\pL\s]+$|u, that validates letters (including accents) and spaces and did not work, I saw that the standard rules that are in the class are like this:

protected $matchTypes = array(
        'i'  => '[0-9]++',
        'a'  => '[0-9A-Za-z]++',
        'h'  => '[0-9A-Fa-f]++',
        '*'  => '.+?',
        '**' => '.++',
        ''   => '[^/\.]++',
    );

I also tried to insert the rule already in the class and also did not succeed, I understand very little of Regex, but it seems that the standard rules are written in a different way and "lean", following this pattern, as I can validate only letters (including with accents), spaces and numbers?

1 answer

1

The expression is correct except for the alternator | which is inserted in its first position. Remove it and leave the expression as follows:

^[\pL\s]+$|u

You can check it working on regex101

If you want to "dry" the expression and make it more readable, you can use:

^[a-zA-ZÀ-ÿ\s]+$

You can check it working on regex101

Browser other questions tagged

You are not signed in. Login or sign up in order to post.