[asterisk-users] a little regex help needed

sean darcy seandarcy2 at gmail.com
Mon Oct 20 17:35:44 CDT 2008


Jared Smith wrote:
> On Mon, 2008-10-20 at 14:10 -0400, sean darcy wrote:
>> exten =>s,n,Set(CALLERID(name)=${IF($[0${CALLERID(num)} = 
>> 0${REGEX("21245711*")} ] ? "Office":${CALLERID(name)} )})
> 
> [snip]
> 
>> What I'd expect is a callerid(num) of 2124571123 to generate an if test 
>> of  [02124571123 == 021245711*] or TRUE.
>>
>> But I've messed up the regex statement somehow.
> 
> In regular expressions, the * means zero or more of the preceding
> character, so the way you have that written means "021245711 and zero or
> more 1s".  What you want instead is "021245711.*", which means
> "021245711 followed by at least on other character".
> 
> Hopefully that sets you on the right path.  Don't forget that Asterisk
> has two regex operators that can be used in expressions as well...
> they're the ':' and '~' operators.
> 
> 

OK. So I changed the * to .. , like so:

exten =>s,n,Set(CALLERID(name)=${IF($[0${CALLERID(num)} = 
0${REGEX("21245711..")} ] ? "Office":${CALLERID(name)} )})

which I would expect to mean 021245711 followed by two other characters.

It still matches a blank callerid(num).

sean




More information about the asterisk-users mailing list