[asterisk-users] escaping regular expression
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? Thanks Klaus ___ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] escaping regular expression
2009/2/4 Klaus Darilion klaus.mailingli...@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 ___ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] escaping regular expression
D Tucny schrieb: 2009/2/4 Klaus Darilion klaus.mailingli...@pernau.at mailto:klaus.mailingli...@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 ___ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] escaping regular expression
2009/2/4 Klaus Darilion klaus.mailingli...@pernau.at D Tucny schrieb: 2009/2/4 Klaus Darilion klaus.mailingli...@pernau.at mailto:klaus.mailingli...@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 + Pretty sure... exten = *56,1,NoOp(Starting regexp test) exten = *56,n,Set(pattern=^[+]\{1\}[0-9]+) exten = *56,n,Set(var=123456789) exten = *56,n,NoOp(${IF(${REGEX(${pattern} ${var})}?Match:No Match)})) exten = *56,n,Set(var=+123456789) exten = *56,n,NoOp(${IF(${REGEX(${pattern} ${var})}?Match:No Match)})) [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'NoOp' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:1] NoOp(SIP/*01-09bd8ff8, Starting regexp test) in new stack [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'Set' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:2] Set(SIP/*01-09bd8ff8, pattern=^[+]\{1\}[0-9]+) in new stack [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'Set' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:3] Set(SIP/*01-09bd8ff8, var=123456789) in new stack [Feb 4 23:49:21] DEBUG[20518] func_strings.c: FUNCTION REGEX (^[+]{1}[0-9]+)(123456789) [Feb 4 23:49:21] DEBUG[20518] pbx.c: Function result is '0' [Feb 4 23:49:21] DEBUG[20518] pbx.c: Function result is 'No Match' [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'NoOp' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:4] NoOp(SIP/*01-09bd8ff8, No Match)) in new stack [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'Set' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:5] Set(SIP/*01-09bd8ff8, var=+123456789) in new stack [Feb 4 23:49:21] DEBUG[20518] func_strings.c: FUNCTION REGEX (^[+]{1}[0-9]+)(+123456789) [Feb 4 23:49:21] DEBUG[20518] pbx.c: Function result is '1' [Feb 4 23:49:21] DEBUG[20518] pbx.c: Function result is 'Match' [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'NoOp' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:6] NoOp(SIP/*01-09bd8ff8, Match)) in new stack So, the \ is still stripped (ast_app_separate_args removes \), but, it doesn't matter as the + is bracketed so it's not the first character after the ^ and so regcomp doesn't fail... d ___ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users
Re: [asterisk-users] escaping regular expression
D Tucny schrieb: 2009/2/4 Klaus Darilion klaus.mailingli...@pernau.at mailto:klaus.mailingli...@pernau.at D Tucny schrieb: 2009/2/4 Klaus Darilion klaus.mailingli...@pernau.at mailto:klaus.mailingli...@pernau.at mailto:klaus.mailingli...@pernau.at mailto:klaus.mailingli...@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 + Pretty sure... exten = *56,1,NoOp(Starting regexp test) exten = *56,n,Set(pattern=^[+]\{1\}[0-9]+) exten = *56,n,Set(var=123456789) exten = *56,n,NoOp(${IF(${REGEX(${pattern} ${var})}?Match:No Match)})) exten = *56,n,Set(var=+123456789) exten = *56,n,NoOp(${IF(${REGEX(${pattern} ${var})}?Match:No Match)})) [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'NoOp' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:1] NoOp(SIP/*01-09bd8ff8, Starting regexp test) in new stack [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'Set' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:2] Set(SIP/*01-09bd8ff8, pattern=^[+]\{1\}[0-9]+) in new stack [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'Set' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:3] Set(SIP/*01-09bd8ff8, var=123456789) in new stack [Feb 4 23:49:21] DEBUG[20518] func_strings.c: FUNCTION REGEX (^[+]{1}[0-9]+)(123456789) [Feb 4 23:49:21] DEBUG[20518] pbx.c: Function result is '0' [Feb 4 23:49:21] DEBUG[20518] pbx.c: Function result is 'No Match' [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'NoOp' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:4] NoOp(SIP/*01-09bd8ff8, No Match)) in new stack [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'Set' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:5] Set(SIP/*01-09bd8ff8, var=+123456789) in new stack [Feb 4 23:49:21] DEBUG[20518] func_strings.c: FUNCTION REGEX (^[+]{1}[0-9]+)(+123456789) [Feb 4 23:49:21] DEBUG[20518] pbx.c: Function result is '1' [Feb 4 23:49:21] DEBUG[20518] pbx.c: Function result is 'Match' [Feb 4 23:49:21] DEBUG[20518] pbx.c: Launching 'NoOp' [Feb 4 23:49:21] VERBOSE[20518] logger.c: -- Executing [...@phonedefault:6] NoOp(SIP/*01-09bd8ff8, Match)) in new stack So, the \ is still stripped (ast_app_separate_args removes \), but, it doesn't matter as the + is bracketed so it's not the first character after the ^ and so regcomp doesn't fail... Ah, the trick is to put the + into [], so it need not be escaped. Thanks Klaus ___ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-users mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-users