VoIP Mailing List Archives
Mailing list archives for the VoIP community |
|
View previous topic :: View next topic |
Author |
Message |
lists at binarus.de Guest
|
Posted: Thu Nov 05, 2015 1:50 am Post subject: [asterisk-users] How to encode plus sign in REGEX function i |
|
|
Dear all,
I have made a fairly complex dialplan where I am using the REGEX function in many places. This works so far, but I wasn't able to solve the following problem. What I would like to do is the following (please note that this is normal regex syntax and obviously not what the REGEX function expects, but I hope it shows the idea):
same => n(A1), GotoIf($[${REGEX("^\+49.*" ${EXTEN})}]?:A2)
This line should make Asterisk jump to label A2 if the extension begins with +49. Since the plus sign is a special char in regexes, I have escaped it with \ as usual. But that does not work; the pattern is not matched and the goto is not executed when the extension begins with +49.
What I already have tried:
1) same => n(A1), GotoIf($[${REGEX("^\\+49.*" ${EXTEN})}]?:A2)
2) same => n(A1), GotoIf($[${REGEX("^\\\+49.*" ${EXTEN})}]?:A2)
3) same => n(A1), GotoIf($[${REGEX("^\\\\+49.*" ${EXTEN})}]?:A2)
4) same => n, Set(REPAT=^+49.*)
same => n(A1), GotoIf($[${REGEX(${REPAT} ${EXTEN})}]?:A2)
5) same => n, Set(REPAT="^+49.*")
same => n(A1), GotoIf($[${REGEX(${REPAT} ${EXTEN})}]?:A2)
6) same => n, Set(REPAT=^+49.*)
same => n(A1), GotoIf($[${REGEX("${REPAT}" ${EXTEN})}]?:A2)
7) same => n, Set(REPAT="^+49.*")
same => n(A1), GotoIf($[${REGEX("${REPAT}" ${EXTEN})}]?:A2)
Neither of these worked.
Actually, the REGEX function is not able to handle normal regular expressions. To make things worse, there doesn't seem to be any documentation. Could anybody please point me to documentation or tell me how write that very simple pattern?
Thank you very much,
Recursive
P.S. This happens in Asterisk 13.6.0 - I haven't tested with other versions.
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello
asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users |
|
Back to top |
|
|
rnewton at digium.com Guest
|
Posted: Fri Nov 06, 2015 8:07 am Post subject: [asterisk-users] How to encode plus sign in REGEX function i |
|
|
On Thu, Nov 5, 2015 at 12:49 AM, Recursive <lists@binarus.de> wrote:
Quote: | Dear all,
I have made a fairly complex dialplan where I am using the REGEX function in many places. This works so far, but I wasn't able to solve the following problem. What I would like to do is the following (please note that this is normal regex syntax and obviously not what the REGEX function expects, but I hope it shows the idea):
same => n(A1), GotoIf($[${REGEX("^\+49.*" ${EXTEN})}]?:A2)
This line should make Asterisk jump to label A2 if the extension begins with +49. Since the plus sign is a special char in regexes, I have escaped it with \ as usual. But that does not work; the pattern is not matched and the goto is not executed when the extension begins with +49.
What I already have tried:
1) same => n(A1), GotoIf($[${REGEX("^\\+49.*" ${EXTEN})}]?:A2)
2) same => n(A1), GotoIf($[${REGEX("^\\\+49.*" ${EXTEN})}]?:A2)
3) same => n(A1), GotoIf($[${REGEX("^\\\\+49.*" ${EXTEN})}]?:A2)
4) same => n, Set(REPAT=^+49.*)
same => n(A1), GotoIf($[${REGEX(${REPAT} ${EXTEN})}]?:A2)
5) same => n, Set(REPAT="^+49.*")
same => n(A1), GotoIf($[${REGEX(${REPAT} ${EXTEN})}]?:A2)
6) same => n, Set(REPAT=^+49.*)
same => n(A1), GotoIf($[${REGEX("${REPAT}" ${EXTEN})}]?:A2)
7) same => n, Set(REPAT="^+49.*")
same => n(A1), GotoIf($[${REGEX("${REPAT}" ${EXTEN})}]?:A2)
Neither of these worked.
Actually, the REGEX function is not able to handle normal regular expressions. To make things worse, there doesn't seem to be any documentation. Could anybody please point me to documentation or tell me how write that very simple pattern?
Thank you very much,
Recursive
P.S. This happens in Asterisk 13.6.0 - I haven't tested with other versions.
|
The documentation for that function is available at the CLI "core show
function REGEX" and is available on the wiki at
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_REGEX
It should be able to handle typical regular expression. I don't see
anything wrong with what you are doing. Please file a bug at
issues.asterisk.org/jira. Do include a debug log on the issue
captured when Asterisk attempts to execute these extensions.
https://wiki.asterisk.org/wiki/display/AST/Collecting+Debug+Information
Thanks,
--
Rusty Newton
Digium, Inc. | Community Support Manager
445 Jan Davis Drive NW - Huntsville, AL 35806 - US
direct: +1 256 428 6200
Check us out at: http://digium.com & http://asterisk.org
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello
asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users |
|
Back to top |
|
|
lists at binarus.de Guest
|
Posted: Mon Nov 09, 2015 8:40 am Post subject: [asterisk-users] How to encode plus sign in REGEX function i |
|
|
On 06.11.2015 14:06, Rusty Newton wrote:
Quote: | On Thu, Nov 5, 2015 at 12:49 AM, Recursive <lists@binarus.de> wrote:
Quote: |
same => n(A1), GotoIf($[${REGEX("^\+49.*" ${EXTEN})}]?:A2)
[..]
Actually, the REGEX function is not able to handle normal regular expressions. To make things worse, there doesn't seem to be any documentation. Could anybody please point me to documentation or tell me how write that very simple pattern?
|
The documentation for that function is available at the CLI "core show
function REGEX" and is available on the wiki at
https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Function_REGEX
|
At first, thank you very much for your reply.
Of course, I had found and read that part of the documentation before posting here. But in this documentation (and any other I came across), I couldn't find any hint about if and how to encode special characters, about what sort of regular expressions are allowed (Perl, extended, Sed etc.), or about what RE engine is used internally. This is what I meant by claiming "no documentation".
I really was hoping to do something wrong. I'll try to file a bug and enable others to reproduce by giving a simple example with standard configuration so that I don't need to upload mine.
Regards,
Recursive
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello
asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users |
|
Back to top |
|
|
lists at binarus.de Guest
|
Posted: Mon Nov 09, 2015 9:06 am Post subject: [asterisk-users] How to encode plus sign in REGEX function i |
|
|
On 06.11.2015 14:06, Rusty Newton wrote:
Thanks to your above hint, I have reviewed my dialplan again and have found a bug in it. After correcting my dialplan, it turned out that you are right (of course): REGEX now behaves like expected.
The reason why I even have thought of REGEX not behaving like expected: The other day I have read some tutorials / articles about variables and strings in Asterisk dialplans. One of them (I really can't remember which one) claimed that there were problems with special characters in strings, for example with the dollar character ($). They recommended to do something like the following *if* such problems would show:
Set(DOLLAR=$)
... head_of_string${DOLLAR}tail_of_string
They also claimed that there were other problematic characters which could be handled the same way. That seemed logic to me and lead me into thinking that the pattern string in the REGEX call could be affected by this; hence my initial post.
I am apologizing that I haven't found the bug in my dialplan at an earlier time.
Best regards,
Recursive
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello
asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users |
|
Back to top |
|
|
oza.4h07 at gmail.com Guest
|
Posted: Mon Nov 09, 2015 9:55 am Post subject: [asterisk-users] How to encode plus sign in REGEX function i |
|
|
2015-11-09 15:06 GMT+01:00 Recursive <lists@binarus.de (lists@binarus.de)>:
Quote: | On 06.11.2015 14:06, Rusty Newton wrote:
Thanks to your above hint, I have reviewed my dialplan again and have found a bug in it. After correcting my dialplan, it turned out that you are right (of course): REGEX now behaves like expected.
|
How would you then recommand to deal with + sign in REGEX ?
Something like 1) ?
1) same => n(A1), GotoIf($[${REGEX("^\\+49.*" ${EXTEN})}]?:A2) |
|
Back to top |
|
|
lists at binarus.de Guest
|
Posted: Tue Nov 10, 2015 2:54 am Post subject: [asterisk-users] How to encode plus sign in REGEX function i |
|
|
On 09.11.2015 15:54, Olivier wrote:
Quote: |
2015-11-09 15:06 GMT+01:00 Recursive <lists@binarus.de <mailto:lists@binarus.de>>:
On 06.11.2015 14:06, Rusty Newton wrote:
Quote: |
It should be able to handle typical regular expression. I don't see
anything wrong with what you are doing. Please file a bug at
issues.asterisk.org/jira <http://issues.asterisk.org/jira>. Do include a debug log on the issue
captured when Asterisk attempts to execute these extensions.
https://wiki.asterisk.org/wiki/display/AST/Collecting+Debug+Information
|
Thanks to your above hint, I have reviewed my dialplan again and have found a bug in it. After correcting my dialplan, it turned out that you are right (of course): REGEX now behaves like expected.
How would you then recommand to deal with + sign in REGEX ?
Something like 1) ?
1) same => n(A1), GotoIf($[${REGEX("^\\+49.*" ${EXTEN})}]?:A2)
|
I was just about writing an additional comment to this thread when I saw your message.
Indeed, after I had corrected the bug in my dialplan, it turned out that at least the backslash obviously must be encoded by doubling it. I don't know if this is a common rule for *all* strings which are used in a dialplan or if it is a rule which is specific to the REGEX function.
I tend to assume the former because otherwise Rusty's statement (REGEX handles usual regular expressions) would be wrong.
In every case, the variant 1) you have cited above is working for me.
Regards,
Recursive
--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
http://www.asterisk.org/hello
asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
http://lists.digium.com/mailman/listinfo/asterisk-users |
|
Back to top |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|