jpwspo
November 14, 2006, 8:35am
1
I ALWAYS get a return code of zero when using regular expressions in the $[ string : expr ]
I’m simply looking for a particular substring 234 within a string 123/234/345/456/ which seems ike a pretty easy task.
exten => 9,n,set(s=123/234/345/456/)
exten => 9,n,set(m=234)
exten => 9,n,set(foo=$[ ${s} : ${m} ])
I tried using =~ instead of : – still get 0.
I tried removing the spaces in line 3 – still get 0.
I tried switching the s and m in the 3rd line (just in case I was reading the docs wrong) – still get 0
but clearly the 234 does exist inside the 123/234/345/456/ so what am I doing wrong here?
BTW when I finally switched to the REGEX function
exten => 9,n,set(foo=${REGEX("${m}" ${s})})
in line 3 it worked. But shouldn’t the first example should work?
Thanks!
http://www.voip-info.org/wiki-Asterisk+variables
specially section named "Substring"
there are examples how : works
jpwspo
November 14, 2006, 11:14pm
3
Thanks for posting a reply, but that’s not correct.
What I’m trying to use is regular expression inside the $[ ] to see if a substring exists insdie the string already.
The documentation at voip-info.org says:
$[expr1 operator expr2]
and under Regular expressions it says
expr1 : regexp
or
expr1 =~ expr2
so something like $[ 123/456/789 : 456 ] SHOULD work, right?
(or maybe =~ instead)
But in my dialplan example above it does not work, it always evaluates to ZERO!
Help!
i’m not english native language user but reading from
http://www.voip-info.org/wiki/view/Asterisk+Expressions
expr1 : regexp
* The ':' operator matches expr1 against regexp, which must be a regular expression. The regular expression is anchored to the beginning of the string with an implicit '^'.
* If the match succeeds and regexp contains at least one regular expression subexpression '\(...\)', the string corresponding to '\1' is returned; otherwise the result returned is the number of characters matched. If the match fails and regexp contains a regular expression subexpression, the null string is returned; otherwise 0.
i would try something like $[ 456 : 123/456/789 ]