Running Linux (Ubuntu 11.10), the same regular expression works in JavaScript, but fails when & is included in the string being evaluated in PHP. Here's what I mean:
JavaScript regex:
regex = /^(?:[a-zA-Z0-9 ',.@&!+-]{3,50})$/;
PHP regex:
$settings['regex_name'] = "/^(?:[a-zA-Z0-9 ',.@&!+-]{3,50})$/";
When the code runs in a browser to verify a string (for example D & L Auto Sales), JavaScript matches the entire string as it should. However, when the server-side code attempts to match on the same string, it fails.
Has anyone run into this before?
EDIT: This is the PHP code that runs the regex:
function validated_array(&$array) {
global $settings;
$filterDefinitions = array( "name" => array('filter' => FILTER_VALIDATE_REGEXP,
'options' => array('regexp' => $settings['regex_name']),
...
);
$retVal = filter_var_array($array, $filterDefinitions);
When the code runs with D & L Auto Sales, $retVal['name'] is empty. However, when I remove the &, $retVal['name'] has a value.
preg_match(). How are you executing the regex match?