[asterisk-users] escaping regular expression

Klaus Darilion klaus.mailinglists at pernau.at
Wed Feb 4 09:04:06 CST 2009



D Tucny schrieb:
> 2009/2/4 Klaus Darilion <klaus.mailinglists at pernau.at 
> <mailto:klaus.mailinglists at pernau.at>>
> 
>     Hi!
> 
>     I am going nuts using REGEXP. I just want to verify if a variable
>     contains a valid +E164 phone number.
> 
>     These, the the pattern is ^\+[0-9]+
> 
>     First I tried:
> 
>       Set(pattern=^\+[0-9]+);
>       if (${REGEX("${pattern}" ${${var}})})
> 
>     but that does not work, the backslash is removed, as seen in the log
>     file:
> 
>       func_strings.c: FUNCTION REGEX (^+[0-9]+)(+4312345
>     <http://www.adaanumber.com/>)
> 
>     So, meanwhile I tried to escape the backslash. I tried:
>       Set(pattern=^\\+[0-9]+);
>       Set(pattern=^\\\+[0-9]+);
>       Set(pattern=^\\\\+[0-9]+);
> 
>     But always the same result:
> 
>       func_strings.c: FUNCTION REGEX (^+[0-9]+)(+4312345)
> 
>     How can I solve this problem?
> 
> 
> Try something like... pattern=^[+]\{1\}[0-9]+

Are you sure? The \ should be in front of the +

klaus



More information about the asterisk-users mailing list