Synopsis
Regular Expression: Returns 1 if data matches regular expression.
Description
REGEX(“<regular expression>” <data>)
Is the regular expression tied to the beginning of the string?
Notes
*CLI> show function REGEX
Return value
Returns 1 if data matches regular expression.
Example
exten => s,1,Set(foo=${REGEX("[abc0-9]" b4)})
— should return 1.
Bugs
The 1.2.10 parser can easily get confused by special characters in your regexp, such as curly braces or the $ anchor. If you suspect that this is the case, put your special characters in a variable as a workaround (ael1 syntax):
what=foo; dollar=$; Verbose(${REGEX("^foo$" foo)}); // 1 Verbose(${REGEX("^foo$" ${what})}); // 0 Verbose(${REGEX("^foo${dollar}" ${what})}); // 1
In addition, the comma character will be replaced with a pipe character inside the regular expression as follows:
Verbose(${REGEX("^[0-9]\{10,15\}$" ${telnum})})
will actually be parsed as:
Verbose(${REGEX("^[0-9]\{10|15\}$" ${telnum})})
To correct this, escape the comma as follows:
Verbose(${REGEX("^[0-9]\{10\,15\}$" ${telnum})})