Removing a prefix

I pretty much run Asterisk personally just to learn it, so I experiment with stuff, and If I break it it’s no big deal. I might have a few questions as I’m figuring things out.

Say, for instance I want to create a fake area code, such as 333 and prefix the number with 1-333, but, I want to remove the 1-333 when the number is dialed on a trunk. Like, if I were to dial 1-333-1308, but only 1308 is passed to the trunk. I used to know how to do this but I forget.

There are examples of this in the sample extensions.conf.

The ${EXTEN} variable properly has the syntax ${EXTEN : x : y } , where x is the starting position and y is the number of digits to return. Given the following dial string:

94169671111

we can extract the following digit strings using the ${EXTEN:x : y } construct:

  • ${EXTEN:1:3} would contain 416
  • ${EXTEN:4:7} would contain 9671111
  • ${EXTEN:-4:4} would start four digits from the end and return four digits, giving us 1111
  • ${EXTEN:2:-4} would start two digits in and exclude the last four digits, giving us 16967
  • ${EXTEN:-6:-4} would start six digits from the end and exclude the last four digits, giving us 67
  • ${EXTEN:1} would give us everything after the first digit, or 4169671111 (if the number of digits to return is left blank, it will return the entire remaining string)
    Building an Interactive Dialplan

This really applies to the ${.....} operator, in general, whether used with variables, functions, or functions, like EXTEN, pretending to be variables.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.