+1  A: 

That's really the best way to do it (without using regex). If you want to use regex (regular expressions), Asterisk 1.1+ has full support for it. This will allow you to do your entire macro in a single line. The documentation for using regex in dialplan is here: voip-info.

Hopefully this helps! There are plenty of examples on that voip-info page that should be able to help you along!

b14ck
Correct me if I'm wrong but when I read the article looks like the implementation of regex in asterisk helps you find a match, great to go on a GotoIf. But how would you replace using the regex?
JorgeO
+1  A: 

Another alternative to what you've done is to use an AGI script. Just write your code in bash/python/etc and use it as AGI(replace,${arg1},${arg2},${arg3}). Might not be as fast as an internal function but it's more compact and potentially faster than your solution.

Farid Fadaie