Freeswitch ESL: regex
Evaluate a regex (regular expression).
Usage:
regex <data>|<pattern>[|<subst string>][|(n|b)] regex m:/<data>/<pattern>[/<subst string>][/(n|b)] regex m:~<data>~<pattern>[~<subst string>][~(n|b)]
This command behaves differently depending upon whether or not a substitution string and optional flag is supplied:
If a subst is not supplied, regex returns either «true» if the pattern finds a match or «false» if not.
If a subst is supplied, regex returns the subst value on a true condition.
If a subst is supplied, on a false (no pattern match) condition regex returns:
the source string with no flag;
with the n flag regex returns null which forces the response «-ERR no reply» from regex;
with the b flag regex returns «false»
The regex delimiter defaults to the | (pipe) character. The delimiter may be changed to ~ (tilde) or / (forward slash) by prefixing the regex with m:
Examples:
regex test1234|\d <== Returns "true" regex m:/test1234/\d <== Returns "true" regex m:~test1234~\d <== Returns "true" regex test|\d <== Returns "false" regex test1234|(\d+)|$1 <== Returns "1234" regex sip:foo@bar.baz|^sip:(.*)|$1 <== Returns "foo@bar.baz" regex testingonetwo|(\d+)|$1 <== Returns "testingonetwo" (no match) regex m:~30~/^(10|20|40)$/~$1 <== Returns "30" (no match) regex m:~30~/^(10|20|40)$/~$1~n <== Returns "-ERR no reply" (no match) regex m:~30~/^(10|20|40)$/~$1~b <== Returns "false" (no match) Logic in revision 14727 if the source string matches the result then the condition was false however there was a match and it is 1001. regex 1001|/(^\d{4}$)/|$1
https://freeswitch.org/confluence/display/FREESWITCH/Regular+Expression