Page 175 - Asterisk™: The Future of Telephony
P. 175
expr1 & expr2
This operator (called “and”) returns the evaluation of expr1 if both expressions
are true (i.e., neither expression evaluates to an empty string or zero). Other-
wise, it returns zero.
expr1 {=, >, >=, <, <=, !=} expr2
These operators return the results of an integer comparison if both arguments
are integers; otherwise, they return the results of a string comparison. The
result of each comparison is 1 if the specified relation is true, or 0 if the relation
is false. (If you are doing string comparisons, they will be done in a manner
that’s consistent with the current local settings of your operating system.)
Mathematical operators
Want to perform a calculation? You’ll want one of these:
expr1 {+, -} expr2
These operators return the results of the addition or subtraction of integer-
valued arguments.
expr1 {*, /, %} expr2
These return, respectively, the results of the multiplication, integer division,
or remainder of integer-valued arguments.
Regular expression operator
You can also use the regular expression operator in Asterisk:
expr1 : expr2
This operator matches expr1 against expr2, where expr2 must be a regular
†
expression. The regular expression is anchored to the beginning of the string
with an implicit ^. ‡
If the match succeeds and the pattern contains at least one regular expression
subexpression—\( ... \)—the string corresponding to \1 is returned; other-
wise, the matching operator returns the number of characters matched. If the
match fails and the pattern contains a regular expression subexpression, the
null string is returned; otherwise, 0 is returned.
In Asterisk version 1.0 the parser was quite simple, so it required that you put at least
one space between the operator and any other values. Consequently, the following
might not have worked as expected:
exten => 123,1,Set(TEST=$[2+1])
† For more on regular expressions, grab a copy of the ultimate reference, Jeffrey E.F. Friedl’s
Mastering Regular Expressions (O’Reilly) or visit http://www.regular-expressions.info.
‡ If you don’t know what a ^ has to do with regular expressions, you simply must obtain a copy of
Mastering Regular Expressions. It will change your life!
Expressions and Variable Manipulation | 147