Search code examples
phpregexzend-frameworkzend-framework2preg-match

PHP 5.6.10 - preg_match(): Compilation failed: invalid range in character class at offset 100


I've following regular expression configured in ZendFrame work routing

'constraints' => array(
 'controller' => '[a-zA-Z0-9_-]*',
 'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
 'dashname' => '[a-zA-Z0-9_-\s]*',
 'formatter' => '[a-zA-Z]*'
 )

throwing error Warning: preg_match(): Compilation failed: invalid range in character class at offset 100 in app\vendor\zendframework\zendframework\library\Zend\Mvc\Router\Http\Segment.php on line 370

Issue seems to be with 'dashname' => '[a-zA-Z0-9_-\s]*',

Same code works in PHP 5.4 version but not in PHP5.6 version, Any help is appreciated.


Solution

  • In class - is a range operator you need to escape it with \

    [a-zA-Z0-9_\-\s]