Translation rule examples
This page collects translation rules that operators ask for most often. Every rule was run through the switch’s translation engine with the sample number shown. Paste a rule into a CLD Translation Rule or CLI Translation Rule field of an account, an authentication rule or a connection, and check it with your own numbers before you rely on it. The syntax is explained in Number translation.
Add, strip or replace a prefix
Section titled “Add, strip or replace a prefix”| Goal | Rule | Number | Result |
|---|---|---|---|
Strip the international prefix 00 |
s/^00// |
00442079460123 |
442079460123 |
Strip 00 or 011 |
s/^(00|011)// |
01138056123456 |
38056123456 |
| Add a prefix | s/^/53872/ |
123 |
53872123 |
Strip a leading + |
s/^\+// |
+442079460123 |
442079460123 |
Add + unless it is already there |
s/^([0-9])/+\1/ |
442079460123 |
+442079460123 |
Replace +1 with 1 |
s/^\+1/1/ |
+123456789 |
123456789 |
Replace +570 with 2222 |
s/^[+]570/2222/ |
+570123456789 |
2222123456789 |
| International to national format | s/^44/0/ |
442079460123 |
02079460123 |
| National to international format | s/^0/44/ |
02079460123 |
442079460123 |
Strip 00, but leave 000 alone |
s/^00([1-9])/\1/ |
00850532166 |
850532166 |
Same rule, number with 000 |
s/^00([1-9])/\1/ |
000850532166 |
000850532166 |
Remove 90 after a 4-character technical prefix that starts with B |
s/^(B...)90/\1/ |
B0439012345678 |
B04312345678 |
| Remove the first five digits | s/^[0-9]{5}// |
666667 |
7 |
Act on the length of the number
Section titled “Act on the length of the number”| Goal | Rule | Number | Result |
|---|---|---|---|
Add 1 to 10-digit numbers |
s/^(\d{10})$/1\1/ |
2125550123 |
12125550123 |
| Same rule, 11-digit number | s/^(\d{10})$/1\1/ |
12125550123 |
12125550123 |
Add 90312 to 10-digit numbers |
s/^(\d{10})$/90312\1/ |
1234567890 |
903121234567890 |
0 followed by 10 digits becomes 90 followed by them |
s/^0(\d{10})$/90\1/ |
01234567890 |
901234567890 |
Add 30 to 8-digit numbers |
s/^(\d{8})$/30\1/ |
12345678 |
3012345678 |
Pad a 1-digit number to 303333333X |
s/^(\d)$/303333333\1/ |
5 |
3033333335 |
Pad a 2-digit number to 30333333XX |
s/^(\d{2})$/30333333\1/ |
52 |
3033333352 |
| Expand a 4-digit extension to a full number | s/^(\d{4})$/0164828\1/ |
6016 |
01648286016 |
Append 0000 to 7-digit numbers |
s/^([0-9]{7})$/\g<1>0000/ |
1234567 |
12345670000 |
| Keep only the first 7 digits | s/^([0-9]{7}).*/\1/ |
1234567890 |
1234567 |
| Drop the first digit of 11-digit numbers | s/^\d(\d{10})$/\1/ |
01234567890 |
1234567890 |
Drop 592 from 7-digit numbers |
s/^592(\d{4})$/\1/ |
5929999 |
9999 |
| Replace CLIs shorter than 10 characters with a fixed CLI | s/^.{0,9}$/0123456789/ |
601612345 |
0123456789 |
| Same rule, 10-digit CLI | s/^.{0,9}$/0123456789/ |
6016123456 |
6016123456 |
| Replace anything of 1 to 6 characters | s/^.{1,6}$/test/ |
abcdeg |
test |
Work with the end of the number
Section titled “Work with the end of the number”| Goal | Rule | Number | Result |
|---|---|---|---|
| Append a suffix | s/$/123/ |
120264765 |
120264765123 |
Replace the suffix 1110 with 1400 |
s/1110$/1400/ |
1234561110 |
1234561400 |
Append 1122 to numbers of the form 90XXX112 |
s/^(90\d{3}112)$/\g<1>1122/ |
90666112 |
906661121122 |
Replace a CLI that ends with 1234 |
s/^.*1234$/unknown/ |
60161231234 |
unknown |
Replace what precedes the last seven digits with 90212 (the first of the seven is 1 to 8) |
s/.*([1-8][0-9]{6})/90212\1/ |
1234567890123 |
902127890123 |
Clean up the format
Section titled “Clean up the format”| Goal | Rule | Number | Result |
|---|---|---|---|
| Remove everything that is not a digit | s/\D//g |
+1 (212) 555-0123 |
12125550123 |
| Remove dots | s/\.//g |
1.233.45 |
123345 |
| Remove spaces | s/ //g |
1 2 3 |
123 |
Turn +90 (310) 988 00 00 into digits |
s/^[+]//;s/[() ]//g |
+90 (310) 988 00 00 |
903109880000 |
Replace or block the whole number
Section titled “Replace or block the whole number”A word such as BLOCK matches no rate, so a CLD rewritten to it is rejected before routing. The call fails with 403 and costs nothing.
| Goal | Rule | Number | Result |
|---|---|---|---|
| Replace every number with a fixed one | 123456 |
999 |
123456 |
| Set a CLI when the caller sent none | s/^$/123456/ |
123456 |
|
| Remove the CLI | s/^.*// |
12345 |
|
| Replace a CLI that contains letters | s/^.*[a-zA-Z].*$/1909/ |
anonymous |
1909 |
| Replace a CLI that contains anything but digits | s/.*[^0-9].*/44444/ |
anonymous |
44444 |
| Prefix a CLI that contains letters | s/^(.*[a-zA-Z].*)$/123\1/ |
anonymous |
123anonymous |
| Repeat the number twice | s/^(.*)$/\1\1/ |
34565 |
3456534565 |
Replace a CLI that contains #91 |
s/^.*#91.*/3444/ |
124a8#9112555615 |
3444 |
Remove letters; if nothing is left, use Blank |
s/[a-zA-Z]//g;s/^$/Blank/ |
hello |
Blank |
| Same rule, digits left over | s/[a-zA-Z]//g;s/^$/Blank/ |
hello123 |
123 |
| Block numbers that contain letters | s/^.*[a-zA-Z].*$/BLOCK/ |
B1231231236016 |
BLOCK |
| Block numbers that are not 12 characters long | s/^(?!.{12}$).*$/BLOCK/ |
12345 |
BLOCK |
Block numbers that do not start with 14 |
s/^(?!14).*$/BLOCK/ |
15 |
BLOCK |
Remove every CLI that does not start with 78565 |
s/^(?!78565).*// |
1785650000 |
|
| Same rule, allowed CLI | s/^(?!78565).*// |
785650000 |
785650000 |
Pass three allowed CLIs and replace every other CLI with the first of them:
s/^(?!90312(1111111|2222222|3333333)$).*$/903121111111/903122222222 stays as it is; 903129999999 becomes 903121111111.
Several substitutions in sequence
Section titled “Several substitutions in sequence”The substitutions of a rule run one after another, each on the result of the previous one. That lets you build conditions, but it also means a later substitution can undo an earlier one. Mark an intermediate result with a character that numbers never contain, such as # or a few letters, and remove the mark at the end.
| Goal | Rule | Number | Result |
|---|---|---|---|
Replace 44 with 222, then 2222 with 55 |
s/^44/222/;s/^2222/55/ |
442333222111 |
55333222111 |
Swap 111 and 222 |
s/^111$/#222/;s/^222$/111/;s/^#// |
111 |
222 |
| Same rule, the other number | s/^111$/#222/;s/^222$/111/;s/^#// |
222 |
111 |
Keep CLIs that start with 962, replace all others |
s/^962/ZYX962/;s/^[0-9].*/96268009996/;s/^ZYX// |
44123 |
96268009996 |
Same rule, CLI with 962 |
s/^962/ZYX962/;s/^[0-9].*/96268009996/;s/^ZYX// |
962123 |
962123 |
Add 011 unless the number starts with +1 |
s/^/011/;s/^011\+1/+1/ |
13058946105 |
01113058946105 |
Same rule, number with +1 |
s/^/011/;s/^011\+1/+1/ |
+13058946105 |
+13058946105 |
Strip 011; keep a leading 1; otherwise add 1 |
s/^/a1/;s/^a1011//;s/^a11/1/;s/^a// |
0112011555 |
2011555 |
Same rule, number with 1 |
s/^/a1/;s/^a1011//;s/^a11/1/;s/^a// |
12125550123 |
12125550123 |
| Same rule, any other number | s/^/a1/;s/^a1011//;s/^a11/1/;s/^a// |
2125550123 |
12125550123 |
In the swap rule, #222 does not match ^222$, so the second substitution leaves it alone; the third removes the mark. Without the mark 111 would become 222 and then 111 again.
Random numbers
Section titled “Random numbers”Rules with ${R:…} give a different result on every call. The results below are examples.
| Goal | Rule | Possible result |
|---|---|---|
Five random characters from 0, 1, 2, 3 and 6 |
s/.*/${R:[0-3,6]5}/ |
16020 |
Fixed prefix +17266 and eight random digits |
s/.*/+17266${R:[0-9]8}/ |
+1726677763170 |
Drop a leading 1, keep the next four digits, add six random digits |
s/^1//;s/^(\d{4}).*$/\1/;s/$/${R:[1-9]1[0-9]4[1-9]1}/ |
2026600081 |
Pick one of six fixed CLIs at random: a random letter first, then one substitution per letter.
s/.*/${R:[a-f]}/;s/^a/+919995346432/;s/^b/+919995000100/;s/^c/+919846000012/;s/^d/+919746532512/;s/^e/+919783252017/;s/^f/+919230456789/Build a CLI from 57, a block 300–305, 310–319 or 320–322, and seven random digits. The letters a, b, c choose the block, so the substitution of one block never matches the output of another:
s/.*/${R:[a-c]}/;s/^a$/5730${R:[0-5]}/;s/^b$/5731${R:[0-9]}/;s/^c$/5732${R:[0-2]}/;s/$/${R:[0-9]7}/A possible result is 573202031518.
Related pages
Section titled “Related pages”- Number translation: where rules are applied and the full syntax
- Route and price calls by CLI or CLD
- Block incoming calls from a CLI
- Test a translation rule (API)