Match zero or more characters but not immediately

It seems like it should be simple, but how do you pattern match zero or more characters like ! does, but without matching immediately?

What we really want to do is:
_[*#0-9]!

And match any extension beginning with a number, * or #, followed by any number of other characters. However the ! matches immediately on transfers, so it doesn’t work for our purpose.

Thanks in advance.

‘X’ matches any digit 0-9
‘Z’ matches any digit 1-9
‘N’ matches any digit 2-9
‘.’ matches 1 or more characters

Does that help?

Thank you, but no not really. The problem is that I can’t see how it’s possible to use those to achieve the desired result.

What about:
_[*#0-9].
or:
_.
?

Tucked in with something like:
_[*#0-9].#
or:
_.#
placed in the same context, to let Asterisk stew over the path (waiting on the trailing #.)

That said, considering…

…is potentially unsafe, especially when doing transfers, depending on your users, dialplan, telco, etc.

That, effectively, matches 2 or more.

That matches 1 or more.

The OP ones 0 or more. I think knowing the use case would help, as it sounds like they have a badly designed numbering plan. I think they would have overlap dialling with a timeout to determine end of number.

Unfortunately there are problems with those suggestions, which is why we couldn’t find a solution ourselves.

_[*#0-9]. requires a minimum length of 2 characters total, whereas we want a minimum of 1.

_. will match extensions which don’t begin with *, #, or 0-9. So for example it will match ‘h’, which we don’t want.

Do you really want to match any number of any character? In my dial plan I have places where I need to match numbers but depending where they came from they might be between 7 and 10 numbers long. To do that I have 4 exten lines, one for each length followed by a goto() line to get to the code that handles them all. As long as the number of lengths is not to many, that’s workable.

Not sure if OP subject " Match zero or more characters but not immediately" matches OP post #1:

Maybe posting some sample strings that you want to match would help…

Here’s a fuller (untested) thought – capture both the 1-char and the 2+ char strings separately:

exten = _[*#0-9],1,NoOp(length of one)
exten = _[*#0-9].,1,NoOp(length of two or more)

It looks like the only solution is to have different extensions for different lengths; at least one for extensions of length 1 and another for 2 or more as penguin suggested above. It’s a shame we can’t do it in one extension, as our extension has many priorities and it’s a bit of a pain to repeat them. It would be nice if Asterisk added a pattern character for this in the future - I suggest maybe “?” to mean 0 or more characters, not matching immediately.
Thanks for all the input!

You only need to repeat priorities that differ between extensions in the context.

Well, the priorities are identical, apart from the extension bit.

You can use .* on any except the first and the ones that actually differ. Using priority numbers s and n can make this easier to code.

Furthering the thought:

exten = _[*#0-9],1,Goto(matched)
exten = _[*#0-9].,1,Goto(matched)
exten = _[*#0-9]!,n(matched),NoOp(matched ${EXTEN})
 same = n,NoOp(something common to all matches)
 same = n,Answer()
 same = n,Playback(tt-monkeys)

I see, thank you for that!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.