from the dial plan:
exten => s,n,NoOp(“test one " ${ REGEX(”[^0-9]" “111****”) } )
exten => s,n,NoOp(“test two " ${ REGEX(”[0-9]" “111****”) } )
from the cl output:
– Executing [s@macro-check-var:6] NoOp(“SIP/xds72moF91-09081678”, "“test one " 1”) in new stack
– Executing [s@macro-check-var:7] NoOp(“SIP/xds72moF91-09081678”, "“test two " 1”) in new stack
not good. why is this happening? am i missing extra bracket or a brace or quotation or… what else is there?
You didn’t say what you were actually trying to accomplish, but I would guess that you wanted to make sure that a value was all numbers…
try something like this…
The ^ on the front says start at the beginning, look for a 0 through 9. Then the {4,8} says find atleast 4 up to 8, but note that in { has to be typed in as { (proper escaping).
sorry… my bad… the search and replace didn’t do it… i was actually after:
exten => s,n,NoOp(“test one " ${REGEX(”[^0-9]" “111”)} )
exten => s,n,NoOp(“test two " ${REGEX(”[0-9]" “111”)} )
it was still returning:
– Executing [s@macro-check-var:6] NoOp(“SIP/xds72moF91-0907b6e8”, "“test one " 1”) in new stack
– Executing [s@macro-check-var:7] NoOp(“SIP/xds72moF91-0907b6e8”, "“test two " 1”) in new stack
the problem were the quotes around the 111. apparently the regex has to be in quotes but the string to check should not be in quotes… go figure…
[macro-check-var]
; ${ARG1} is the var
; ${ARG2} is the lenght var should be
exten => s,1,NoOp(“in the check var macro”)
exten => s,n,Set(len-pass=$[ “${LEN(${ARG1})}” = “${ARG2}” ] )
exten => s,n,Set(reg-pass=${REGEX("[^0-9]" ${ARG1} )})
exten => s,n,Set(reg-mass=${REGEX("[^0-9]" 111111111 )}) ;; <= this is hard coded…
output…
– User entered ‘111111111’
…
– Executing [s@enter-card:200] Macro(“SIP/xds72moF91-090819d0”, “check-var|111111111|9”) in new stack
– Executing [s@macro-check-var:1] NoOp(“SIP/xds72moF91-090819d0”, ““in the check var macro””) in new stack
– Executing [s@macro-check-var:2] Set(“SIP/xds72moF91-090819d0”, "len-pass=1 ") in new stack
– Executing [s@macro-check-var:3] Set(“SIP/xds72moF91-090819d0”, “reg-pass=1”) in new stack
– Executing [s@macro-check-var:4] Set(“SIP/xds72moF91-090819d0”, “reg-mass=1”) in new stack
how come reg-pass is 1?! how about reg-mass?! they both should be 0…
Your not understanding how the reqex works. What exactly are you trying to accomplish? Is the thing supposed to be checking to see if the password is only numbers?
This is true, because your saying find me not a 0. The first character is a 1. So its true.
If you want to make sure the password is only numbers do this…
This is true, because your saying find me not a 0. The first character is a 1. So its true.
[/quote]
wrong. the class [^0-9] means “match everything but numbers”. it doesn’t mean ’ find me not a 0’. it says “find me anything that is not 0 or 1 or 2… or 9 in ${ARG1}”.
so if ${ARG1} == 111111111 the above test should be false.
this should work (have not tested): ${REGEX("^[0-9]{${ARG2}}. it’s just a different way of putting it. it says 'find me a string of ${ARG2} continuous digits starting from the beginning of ${ARG1}. so if the string is ${ARG2} long and it has only digits in it, your suggestion would work.
so in this particular case your suggestion is applicable. in the real world of regex however [^0-9] and ^[0-9]{${ARG2}} are very different things…