Jonathan H
2016-Oct-13 10:54 UTC
[asterisk-users] Match one OR two digit extension not working as expected without using "dangerous" _. pattern (Ast 14)
Back to basics here. I want to match on one OR two digits. The following two both work, but ONLY for more than one digit, which is not as expected from the docs (see below). exten => _X.,1,SayNumber(${EXTEN}) exten => _[0-9].,1,SayNumber(${EXTEN}) This next one will ONLY match 2 digits, as expected, but the first two SHOULD match one or more, right? exten => _XX,1,SayNumber(${EXTEN}) The following pattern works, but I thought it was "dangerous" and to be discouraged? exten => _.,1,SayNumber(${EXTEN}) So, again, if someone dials 1 and a one second delay passes, I want it to say 1. If someone dials 1 then another 1 within a second then I want it to be 11, and 111 should be invalid. (I've Set(TIMEOUT(digit)=1) ) Yes, I can do this with multiple lines, but the docs suggest this should be easily do-able in 1 line, and I don't want to double the amount of dialplan (there'll be a few of these!). Here are my references: --------------------------------------------------- https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching The letter X or x represents a single digit from 0 to 9. The period character (.) at the end of a pattern matches one or more remaining characters. You put it at the end of a pattern when you want to match extensions of an indeterminate length. --------------------------------------------------- Page 141 of the Asterisk Definitive Guide 4th Edition: . (period) Wildcard match; matches one or more characters, no matter what they are. If you?re not careful, wildcard matches can make your dialplans do things you?re not expecting (like matching built-in extensions such as i or h). You should use the wildcard match in a pattern only after you?ve matched as many other digits as possible. For example, the following pattern match should probably never be used: _. In fact, Asterisk will warn you if you try to use it. Instead, if you really need a catchall pattern match, use this one to match all strings that start with a digit followed by one or more characters (see ! if you want to be able to match on zero or more characters): _X. Or this one, to match any alphanumeric string: _[0-9a-zA-Z]. --------------------------------------------------- http://www.voip-info.org/wiki/view/Asterisk+Dialplan+Patterns Do not use a pattern of _. as this will match everything including Asterisk special extensions like i, t, h, etc. Instead use something like _X. or _X which will not match __special__ extensions.. So what do you use instead of _. ? Many examples use this construct, but if you use it you may see a warning message in the log advising you to change _. to _X. ---------------------------------------------------
Jean Aunis
2016-Oct-13 11:05 UTC
[asterisk-users] Match one OR two digit extension not working as expected without using "dangerous" _. pattern (Ast 14)
You can use the "!" character : exten => _X!,1,SayNumber(${EXTEN}) Best regards Jean Aunis Le 13/10/2016 ? 12:54, Jonathan H a ?crit :> Back to basics here. I want to match on one OR two digits. > > The following two both work, but ONLY for more than one digit, which > is not as expected from the docs (see below). > > exten => _X.,1,SayNumber(${EXTEN}) > exten => _[0-9].,1,SayNumber(${EXTEN}) > > > This next one will ONLY match 2 digits, as expected, but the first two > SHOULD match one or more, right? > > exten => _XX,1,SayNumber(${EXTEN}) > > The following pattern works, but I thought it was "dangerous" and to > be discouraged? > exten => _.,1,SayNumber(${EXTEN}) > > So, again, if someone dials 1 and a one second delay passes, I want it to say 1. > If someone dials 1 then another 1 within a second then I want it to be > 11, and 111 should be invalid. > > (I've Set(TIMEOUT(digit)=1) ) > > Yes, I can do this with multiple lines, but the docs suggest this > should be easily do-able in 1 line, and I don't want to double the > amount of dialplan (there'll be a few of these!). > > Here are my references: > > --------------------------------------------------- > > https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching > > The letter X or x represents a single digit from 0 to 9. > The period character (.) at the end of a pattern matches one or more > remaining characters. You put it at the end of a pattern when you want > to match extensions of an indeterminate length. > > --------------------------------------------------- > > Page 141 of the Asterisk Definitive Guide 4th Edition: > > . (period) > Wildcard match; matches one or more characters, no matter what they are. > If you?re not careful, wildcard matches can make your dialplans do > things you?re not expecting (like matching built-in extensions such > as i or h). You should use the wildcard match in a pattern only after > you?ve matched as many other digits as possible. For example, the > following pattern match should probably never be used: > _. > In fact, Asterisk will warn you if you try to use it. Instead, if you > really need a catchall pattern match, use this one to match all strings > that start with a digit followed by one or more characters (see ! if > you want to be able to match on zero or more characters): > _X. > Or this one, to match any alphanumeric string: > _[0-9a-zA-Z]. > > --------------------------------------------------- > > http://www.voip-info.org/wiki/view/Asterisk+Dialplan+Patterns > Do not use a pattern of _. as this will match everything including > Asterisk special extensions like i, t, h, etc. Instead use something > like _X. or _X which will not match __special__ extensions.. > So what do you use instead of _. ? Many examples use this construct, > but if you use it you may see a warning message in the log advising > you to change _. to _X. > > --------------------------------------------------- >
Jonathan H
2016-Oct-13 11:09 UTC
[asterisk-users] Match one OR two digit extension not working as expected without using "dangerous" _. pattern (Ast 14)
Sorry, I should have said, I already tried "!". It matches immediately and doesn't wait for a second digit. On 13 October 2016 at 12:05, Jean Aunis <jean.aunis at prescom.fr> wrote:> You can use the "!" character : > > exten => _X!,1,SayNumber(${EXTEN}) > > > Best regards > > Jean Aunis > > > Le 13/10/2016 ? 12:54, Jonathan H a ?crit : >> >> Back to basics here. I want to match on one OR two digits. >> >> The following two both work, but ONLY for more than one digit, which >> is not as expected from the docs (see below). >> >> exten => _X.,1,SayNumber(${EXTEN}) >> exten => _[0-9].,1,SayNumber(${EXTEN}) >> >> >> This next one will ONLY match 2 digits, as expected, but the first two >> SHOULD match one or more, right? >> >> exten => _XX,1,SayNumber(${EXTEN}) >> >> The following pattern works, but I thought it was "dangerous" and to >> be discouraged? >> exten => _.,1,SayNumber(${EXTEN}) >> >> So, again, if someone dials 1 and a one second delay passes, I want it to >> say 1. >> If someone dials 1 then another 1 within a second then I want it to be >> 11, and 111 should be invalid. >> >> (I've Set(TIMEOUT(digit)=1) ) >> >> Yes, I can do this with multiple lines, but the docs suggest this >> should be easily do-able in 1 line, and I don't want to double the >> amount of dialplan (there'll be a few of these!). >> >> Here are my references: >> >> --------------------------------------------------- >> >> https://wiki.asterisk.org/wiki/display/AST/Pattern+Matching >> >> The letter X or x represents a single digit from 0 to 9. >> The period character (.) at the end of a pattern matches one or more >> remaining characters. You put it at the end of a pattern when you want >> to match extensions of an indeterminate length. >> >> --------------------------------------------------- >> >> Page 141 of the Asterisk Definitive Guide 4th Edition: >> >> . (period) >> Wildcard match; matches one or more characters, no matter what they are. >> If you?re not careful, wildcard matches can make your dialplans do >> things you?re not expecting (like matching built-in extensions such >> as i or h). You should use the wildcard match in a pattern only after >> you?ve matched as many other digits as possible. For example, the >> following pattern match should probably never be used: >> _. >> In fact, Asterisk will warn you if you try to use it. Instead, if you >> really need a catchall pattern match, use this one to match all strings >> that start with a digit followed by one or more characters (see ! if >> you want to be able to match on zero or more characters): >> _X. >> Or this one, to match any alphanumeric string: >> _[0-9a-zA-Z]. >> >> --------------------------------------------------- >> >> http://www.voip-info.org/wiki/view/Asterisk+Dialplan+Patterns >> Do not use a pattern of _. as this will match everything including >> Asterisk special extensions like i, t, h, etc. Instead use something >> like _X. or _X which will not match __special__ extensions.. >> So what do you use instead of _. ? Many examples use this construct, >> but if you use it you may see a warning message in the log advising >> you to change _. to _X. >> >> --------------------------------------------------- >> > > > -- > _____________________________________________________________________ > -- Bandwidth and Colocation Provided by http://www.api-digital.com -- > > Join the Asterisk Community at the 13th AstriCon, September 27-29, 2016 > http://www.asterisk.org/community/astricon-user-conference > > New to Asterisk? Start here: > https://wiki.asterisk.org/wiki/display/AST/Getting+Started > > asterisk-users mailing list > To UNSUBSCRIBE or update options visit: > http://lists.digium.com/mailman/listinfo/asterisk-users
Tony Mountifield
2016-Oct-13 12:18 UTC
[asterisk-users] Match one OR two digit extension not working as expected without using "dangerous" _. pattern (Ast 14)
In article <CAEebyNV+64CsK0N5+Jwn-c1qgt9ai7E-yMu_OaMayavGQ5tfOQ at mail.gmail.com>, Jonathan H <lardconcepts at gmail.com> wrote:> Back to basics here. I want to match on one OR two digits. > > The following two both work, but ONLY for more than one digit, which > is not as expected from the docs (see below). > > exten => _X.,1,SayNumber(${EXTEN}) > exten => _[0-9].,1,SayNumber(${EXTEN}) > > > This next one will ONLY match 2 digits, as expected, but the first two > SHOULD match one or more, right? > > exten => _XX,1,SayNumber(${EXTEN}) > > The following pattern works, but I thought it was "dangerous" and to > be discouraged? > exten => _.,1,SayNumber(${EXTEN}) > > So, again, if someone dials 1 and a one second delay passes, I want it to say 1. > If someone dials 1 then another 1 within a second then I want it to be > 11, and 111 should be invalid. > > (I've Set(TIMEOUT(digit)=1) ) > > Yes, I can do this with multiple lines, but the docs suggest this > should be easily do-able in 1 line, and I don't want to double the > amount of dialplan (there'll be a few of these!).When matching an extension being dialled, Asterisk is only concerned about priority 1, so that's the only priority you need to double. You should be able to use ! safely in priority 2 upwards: exten => _X,1,NoOp(Matching single digit) exten => _X.,1,NoOp(Matching multiple digits) exten => _X!,2,SayNumber(${EXTEN}) exten => _X!,3,Etc.. Disclaimer: I haven't tested this. Cheers Tony -- Tony Mountifield Work: tony at softins.co.uk - http://www.softins.co.uk Play: tony at mountifield.org - http://tony.mountifield.org
Jonathan H
2016-Oct-14 12:55 UTC
[asterisk-users] Match one OR two digit extension not working as expected without using "dangerous" _. pattern (Ast 14)
On 13 October 2016 at 13:18, Tony Mountifield <tony at softins.co.uk> wrote:> exten => _X,1,NoOp(Matching single digit) > exten => _X.,1,NoOp(Matching multiple digits) > exten => _X!,2,SayNumber(${EXTEN}) > exten => _X!,3,Etc..Thanks - I appreciate the idea, but it matches more than 2 digits. But, thanks to your info, I cobbled together something that works, and matches only 1 or 2 digits in what I think is the most compact way, by sending a 1 digit extension to the 2 digit matcher, prefixed with a 0. Example which works: [extentest] exten => s,1,Set(TIMEOUT(digit)=1) same => n,BackGround(extension) same => n,WaitExten(5) exten => _X,1,Goto(0${EXTEN},1) exten => _XZ,1,SayNumber(${EXTEN}) same => n,Goto(s,1) exten => e,1,Goto(s,1) ***HOWEVER!!!!*** Do I need to report a bug? Either: A: All the documentation is wrong and ". (period) Wildcard match; matches one or more characters" is NOT actually how Asterisk works. or B: The documentation is correct and Asterisk's "one of more character matching" routine is wrong or C: I've completely misunderstood what "matches one of more characters" means :) What's the consensus? Thanks!