<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
<font face="Arial">Greetings,<br>
<br>
I'm running 1.2.7.1, and I'm trying to using the REGEX function in my
dialplan. However, the Asterisk parser doesn't seem to understand
what's going on. I'm trying to use REGEX to determine if a variable
matches a standard 10 digit US/Canada number. To do this, I started
with the following:<br>
<br>
exten => _76.,1,Set(isnum=${REGEX("[2-9][0-9]{2}[2-9][0-9]{6}"
${EXTEN:2})})<br>
exten => _76.,2,GotoIf($["${isnum}" = "1"] ? 3:5)<br>
[...]<br>
<br>
Where the regular expression says: match digit 2-9, then digit 0-9
twice, then digit 2-9, then digit 0-9 six times.<br>
<br>
The first problem is obviously that the curly braces used in regex
patterns to denote repeating patterns means something different to
Asterisk. I would expect back-slashing to fix this. So...<br>
<br>
</font><font face="Arial">exten =>
_76.,1,Set(isnum=${REGEX("[2-9][0-9]\{2\}[2-9][0-9]\{6\}" ${EXTEN:2})})<br>
<br>
However, this doesn't solve the problem. When I execute the above
dialplan (with the modified line 1 I just listed), I get this:<br>
<br>
May 16 10:49:10 WARNING[27970]: pbx.c:1366 ast_func_read: Can't find
trailing parenthesis?<br>
May 16 10:49:10 WARNING[27970]: func_strings.c:105
builtin_function_regex: Malformed input REGEX("[2-9][0-9]{2): braces
not balanced<br>
-- Executing Set("SIP/1000-efb2", "isnum=0[2-9][0-9]{6}"
1234567890)}") in new stack<br>
May 16 10:49:10 WARNING[27970]: ast_expr2.fl:183 ast_yyerror:
ast_yyerror(): syntax error: syntax error, unexpected TOKEN, expecting
$end; Input:<br>
"0[2-9][0-9]{6}" 1234567890)}" = "1"<br>
^<br>
May 16 10:49:10 WARNING[27970]: ast_expr2.fl:187 ast_yyerror: If you
have questions, please refer to doc/README.variables in the asterisk
source.<br>
-- Executing GotoIf("SIP/1000-efb2", ""0[2-9][0-9]{6}" ? 3:5") in
new stack<br>
<br>
The carat is pointing to the number 1 just past the closing quote of
the regex pattern.<br>
<br>
It seems like the dialplan parser is ignoring the back-slashed curly
braces denoting the repeating patterns in the regex and instead parsing
them, causing the REGEX function to get malformed data. I've fixed
this by unrolling the entire pattern, i.e.:<br>
<br>
exten =>
_76.,1,Set(isnum=${REGEX("[2-9][0-9][0-9][2-9][0-9][0-9][0-9][0-9][0-9][0-9]"
${EXTEN:2})})<br>
<br>
While this works, and isn't too ugly, if I had to repeat some other,
longer, pattern it would get nasty quickly. What magic incantation do
I need to perform to get pattern matching to work correctly in the
REGEX function?<br>
<br>
Cheers,<br>
-Wes<br>
<br>
</font>
</body>
</html>