diff --git a/resources/functions.php b/resources/functions.php index b5a0d42c0e..9ab0c45299 100644 --- a/resources/functions.php +++ b/resources/functions.php @@ -1757,11 +1757,15 @@ function number_pad($number,$n) { //converts a string to a regular expression if (!function_exists('string_to_regex')) { - function string_to_regex($string) { + function string_to_regex($string, $prefix='') { //escape the plus if (substr($string, 0, 1) == "+") { $string = "^\\+(".substr($string, 1).")$"; } + //add prefix + if (strlen($prefix) > 0) { + $prefix = $prefix.'?'; + } //convert N,X,Z syntax to regex $string = str_ireplace("N", "[2-9]", $string); $string = str_ireplace("X", "[0-9]", $string); @@ -1774,10 +1778,10 @@ function number_pad($number,$n) { if (substr($string, -1) != "$") { $string = $string."$"; } - //add the round brackgets ( and ) + //add the round brackets ( and ) if (!strstr($string, '(')) { if (strstr($string, '^')) { - $string = str_replace("^", "^(", $string); + $string = str_replace("^", "^".$prefix."(", $string); } else { $string = '^('.$string;