[asterisk-users] escaping regular expression

D Tucny d at tucny.com
Wed Feb 4 08:38:30 CST 2009


2009/2/4 Klaus Darilion <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]+

d
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20090204/4bd4efd1/attachment.htm 


More information about the asterisk-users mailing list