|
Greetings, 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: exten => _76.,1,Set(isnum=${REGEX("[2-9][0-9]{2}[2-9][0-9]{6}" ${EXTEN:2})}) exten => _76.,2,GotoIf($["${isnum}" = "1"] ? 3:5) [...] Where the regular _expression_ says: match digit 2-9, then digit 0-9 twice, then digit 2-9, then digit 0-9 six times. 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... exten => _76.,1,Set(isnum=${REGEX("[2-9][0-9]\{2\}[2-9][0-9]\{6\}" ${EXTEN:2})}) However, this doesn't solve the problem. When I execute the above dialplan (with the modified line 1 I just listed), I get this: May 16 10:49:10 WARNING[27970]: pbx.c:1366 ast_func_read: Can't find trailing parenthesis? 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 -- Executing Set("SIP/1000-efb2", "isnum=0[2-9][0-9]{6}" 1234567890)}") in new stack May 16 10:49:10 WARNING[27970]: ast_expr2.fl:183 ast_yyerror: ast_yyerror(): syntax error: syntax error, unexpected TOKEN, expecting $end; Input: "0[2-9][0-9]{6}" 1234567890)}" = "1" ^ 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. -- Executing GotoIf("SIP/1000-efb2", ""0[2-9][0-9]{6}" ? 3:5") in new stack The carat is pointing to the number 1 just past the closing quote of the regex pattern. 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.: 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})}) 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? Cheers, -Wes |
_______________________________________________ --Bandwidth and Colocation provided by Easynews.com --
Asterisk-Users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
