[asterisk-users] Pattern matching repeating digits

Nathan Anderson nathana at fsr.com
Wed Mar 27 01:18:27 CDT 2013


'lo, all,

Is there some (possibly undocumented?) way that I can pattern-match on a specified number of repeating digits?  (Something similar to regular expressions' {})

Here's an example: let's say I have a string of things that need to be done for both extensions 233 and 255.  I can either...

A) Repeat the exact same code for both extensions, like so:

exten => 233,1,DoStuff()
exten => 233,n,AndMoreStuff()
exten => 233,n,Dial(something)

exten => 255,1,DoStuff()
exten => 255,n,AndMoreStuff()
exten => 255,n,Dial(something)

...which is stupid, or...

B) I can attempt code reuse for similar cases (a Good Thing[tm]), and make as specific of a match as possible, like so:

exten => _2[35][35],1,DoStuff()
exten => _2[35][35],n,AndMoreStuff()
exten => _2[35][35],n,Dial(something)

...but this will not only match 233 and 255, but 235 and 253 as well.

It'd be nice if there was a substitute character that meant "a character that is exactly the same as the preceding one"; for example, if R was meant to represent such a concept, then this would do what I want:

exten => _2[35]R,1,DoStuff()
exten => _2[35]R,n,AndMoreStuff()
exten => _2[35]R,n,Dial(something)

You could even do crazy things like chain them together (this would match 23333 and 25555 and nothing else);

exten => _2[35]RRR,1,DoStuff()
exten => _2[35]RRR,n,AndMoreStuff()
exten => _2[35]RRR,n,Dial(something)

Am I missing something or does this really not exist?

Thanks,

-- 
Nathan Anderson
First Step Internet, LLC
nathana at fsr.com



More information about the asterisk-users mailing list