Summary:ASTERISK-06804: Function REGEX gets confused when using curly braces in a regular expression
Reporter:Leif Madsen (lmadsen)Labels:
Date Opened:2006-04-18 12:32:21Date Closed:2011-06-07 14:07:28
Versions:Frequency of
Description:As brought up in the developers conference call, and confirmed to be a bug by Kevin, I'm opening this bug.

It seems that Asterisk gets confused when using curly braces inside the REGEX dialplan function. Kevin has mentioned the problem is around like 1478 of pbx.c, and I'll have to spend some time tomorrow looking for the problem unless of course someone else gets a chance to look at it before me :)

I've posted the error below.

Here is the dialplan line (I'm basically performing a check to determine if a variable is a 10 digit number, but I've placed actual numbers instead of a variable for simplicity)

exten => s,n,GotoIf($[${REGEX("\d{10}" 1234567890)}]?valid)


2006-04-15 15:05:53 WARNING[1856]: pbx.c:1365 ast_func_read: Can't find trailing parenthesis?
2006-04-15 15:05:53 WARNING[1856]: func_strings.c:105 builtin_function_regex: Malformed input REGEX("d{10): Unmatched \{
"2006-04-15 15:05:53 WARNING[1856]: ast_expr2.fl:183 ast_yyerror: ast_yyerror(): syntax error: syntax error, unexpected TOKEN, expecting $end; Input:
0" 1234567890)}

BTW: Version is actually 1.2.7, but there is no 1.2.7 in the Version list.
Comments:By: Leif Madsen (lmadsen) 2006-04-18 12:35:04

As per Kevin, work around for 1.2.x branch is as follows:

exten => s,n,Set(regtomatch=\d{10})
exten => s,n,GotoIf($[${REGEX(${regtomatch} 1234567890)}]?valid)

By: Leif Madsen (lmadsen) 2006-04-20 19:10:27

Also of note with the above method:

- do not place double or single quotes around the value being assigned to regtomatch
- characters such as , (comma) need to be espcaped with \

By: Leif Madsen (lmadsen) 2006-04-20 19:34:56

I don't think this is actually an issue anymore -- if you use something like:

exten => s,n,GotoIf($[${REGEX("/^\d{10}$/" ${CALLERID(number)})}]?valid)

...then it works fine -- you need open the regular expression correctly I guess :)

Of note though -- you do still need to escape any characters the Asterisk parser might manipulate (commas -> pipes for example)