Regular expression

You will frequently use some regular expressions when you configure number substitution rules. Regular expressions are a powerful and flexible tool for pattern matching and substitution. They are not restricted to a language or system and are widely accepted.

When using a regular expression, you need to construct a matching pattern according to certain rules, and then compare the matching pattern with the target object. The simplest regular expressions do not contain any metacharacter. For example, you can specify the regular expression "hello", which matches only the string "hello".

To help you construct flexible matching patterns, regular expressions support some special characters, called metacharacters, which define the way other characters appear in the target object. Table 12 describes these metacharacters.

Table 12: Metacharacters

Metacharacter

Meaning

0-9

Digits 0 through 9.

Pound sign (#) and asterisk (*)

Each indicates a valid digit.

Dot (.)

Wildcard, which can match any valid digit. For example, 555…. can match any number beginning with 555 and ending in four additional characters.

Hyphen (-)

Used to connect two numbers (The smaller comes before the larger) to indicate a range of numbers, for example, 1-9 inclusive.

Brackets ([ ])

Delimits a range for matching. It can be used together with signs such as !, %, and +. For example, [235-9] indicates one number of 2, 3, and 5 through 9.

Parentheses (( ))

Indicates a sub-expression. For example, (086) indicates the character string 086. It is usually used together with signs such as !, %, and +. For example, (086)!010 can match two character strings 010 and 086010.

Exclamation point (!)

A control character, indicating that the sub-expression before it appears once or does not appear. For example, (010)!12345678 can match 12345678 and 01012345678.

Plus sign (+)

A control character, indicating that the sub-expression before it appears one or more times. However, if a calling number starts with the plus sign, the sign itself does not have special meanings and only indicates that the following is an effective number and the whole number is E.164-compliant. For example, 9876(54)+ can match 987654, 98765454, 9876545454, and so on, and +110022 is an E.164-compliant number.

Percent sign (%)

A control character, indicating that the sub-expression before it appears multiple times or does not appear. For example, 9876(54)% can match 9876, 987654, 98765454, 9876545454, and so on.

The sub-expression (one digit or digit string) before a control character such as exclamation point (!), plus sign (+), and percent sign (%) can appear for the corresponding times indicated by the control character. For example, (100)+ can match 100, 100100, 100100100, and so on. Once any number of them is matched, the match is considered an exact match. In the longest match mode, the voice gateway will ignore subsequent digits dialed by the subscriber after an exact match. (For the case that the gateway needs to wait for subscribers to continue dialing after an exact match, see the description for T mode.)

The characters (\) and (|) are mainly used in regular expressions and cannot be used as common characters. The character (\) is an escape character. If you want a control character to represent itself, you need to add the escape character (\) before it. For example, (\+) represents the character (+) itself because (+) is a control character in regular expressions. The character (|) means that the current character (string) is the character (string) on either the left or the right. For example, 0860108888|T means that the current character string is either 0860108888 or T.

T mode—The character T in the match-template match-string means that the voice gateway should wait for more digits until the number exceeds the maximum length or the dial timer expires.

If a number starts with the plus sign (+), note the following when you use it on a trunk: the E&M, R2, and LGS signaling uses DTMF, and as the plus sign (+) does not have a corresponding audio, the number cannot be transmitted to the called side successfully. While the DSS1 signaling uses ISDN transmission, the above problem does not exist. Therefore, you should avoid using a number that cannot be identified by the signaling itself; otherwise, the call will fail.