Problem picking string type with Router AltoRouter

1

I'm using AltoRouter to make the page call of my project, and in the doc it says that to use "Custom Match Types" just add

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

However, I tried using this rule: |^[\pL\s]+$|u , which validates letters (including accents) and spaces and did not work, I saw that the default 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 and "lean" way, following this pattern, how can I validate only letters (including accents), spaces and numbers?

    
asked by anonymous 16.12.2016 / 04:45

1 answer

1

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

^[\pL\s]+$|u

You can check it working at regex101

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

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

You can check it out at regex101

    
16.12.2016 / 13:46