[Freeswitch-users] Need help on regex

Steven Ayre steveayre at gmail.com
Mon Oct 25 01:00:04 PDT 2010


Yes, \d\d\d and \d{3} are equivalent... use whichever you prefer.

You can have both in a single regex, but since they won't be matched
within the same brackets they'll not be in the same variable.

^\d{3}(0\d{4})\d{2}$|^(\d{3}[1-9]\d{6})$
with a zero would be in $1, $2 will be null
and without a zero would be in $2, $1 will be null

So I can't think of a way to handle both in the same extension... You
could have both transfer to a third extension where the call is
handled though if you want to avoid duplicated actions in the
dialplan.

Unless FS supports named captures:
^\d{3}(?<num>0\d{4})\d{2}$|^(?<num>\d{3}[1-9]\d{6})$

In which case it's be stored in $num (?) in both cases, but I don't
know whether FS's implementation supports named capturing...

-Steve


On 25 October 2010 02:39, mazilo <Nabble at slickdeals.endjunk.com> wrote:
>
>
> Steven Ayre wrote:
>>
>> <extension name="zero">
>>   <condition field="destination_number"
>> expression="^\d\d\d(0\d\d\d\d)\d\d$">
>>     <!-- $1 holds the number -->
>>   </condition>
>> </extension>
>> <extension name="nonzero">
>>   <condition field="destination_number"
>> expression="^(\d\d\d[123456789]\d\d\d\d\d\d)$">
>>     <!-- $1 holds the number -->
>>   </condition>
>> </extension>
>>
>> Steve on iPhone
> Steven, thank you for your quick response. I reckon the \d\d\d is the same
> as \d{3} such that above expressions can be rewritten as
> expression="^\d{3}(0\d{4})\d{2}$" and expression="^(\d{3}[1-9]\d{6})$",
> respectively. If so, is it possible to combine the two regex expressions
> into a single expression using pipe within one dialplan? I tried
> expression="^\d{3}(0\d{4})\d{2}$|^(\d{3}[1-9]\d{6})$" and it only works for
> the 1st regex while the 2nd regex gives a null.
>
> -----
> don't and stop are the ONLY two 4-letter words considered offensive to men,
> but not when used together.
> --
> View this message in context: http://freeswitch-users.2379917.n2.nabble.com/Need-help-on-regex-tp5668666p5669081.html
> Sent from the freeswitch-users mailing list archive at Nabble.com.
>
> _______________________________________________
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>



More information about the FreeSWITCH-users mailing list