I am not much of a regex person but am looking for some help on crafting a simple regex filter that can do the following criterias: 1. The dialed number is always a 10-digits number, i.e. an area code + 7-digits number (without any leading digit(s) of +1 and/or 1). 2. If the 4-th digit of the dialed number (after the area code) is a non-zero number, do nothing. Otherwise, the regex filter will strip the leading 3 digits (area code) as well as the last 2 digits number and this will leave only 1-st 5-digits number (no area code). For instance, if the 10-digits dialed number is 0120123456, then the regex filter will return 01234. More examples followed: 10-digits input number output number --------------------- ------------- 4120123456 01234 0121234567 0121234567 1310156434 01564 8231234567 8231234567 0126543210 0126543210 Anyone? Thanks. ----- 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-tp5668666p5... Sent from the freeswitch-users mailing list archive at Nabble.com.
<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 On 24 Oct 2010, at 22:09, mazilo <Nabble@slickdeals.endjunk.com> wrote:
I am not much of a regex person but am looking for some help on crafting a simple regex filter that can do the following criterias:
1. The dialed number is always a 10-digits number, i.e. an area code + 7-digits number (without any leading digit(s) of +1 and/or 1).
2. If the 4-th digit of the dialed number (after the area code) is a non-zero number, do nothing. Otherwise, the regex filter will strip the leading 3 digits (area code) as well as the last 2 digits number and this will leave only 1-st 5-digits number (no area code). For instance, if the 10-digits dialed number is 0120123456, then the regex filter will return 01234. More examples followed:
10-digits input number output number --------------------- ------------- 4120123456 01234 0121234567 0121234567 1310156434 01564 8231234567 8231234567 0126543210 0126543210 Anyone? Thanks.
----- 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-tp5668666p5... Sent from the freeswitch-users mailing list archive at Nabble.com.
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
Apart from the numerous regex help on the net, I have found a very good helper to the open source text editor Notepad++, which got me out of my regex woes a couple of months ago. Regards HASSAN On 2010-10-25, Steven Ayre <steveayre@gmail.com> 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
On 24 Oct 2010, at 22:09, mazilo <Nabble@slickdeals.endjunk.com> wrote:
I am not much of a regex person but am looking for some help on crafting a simple regex filter that can do the following criterias:
1. The dialed number is always a 10-digits number, i.e. an area code + 7-digits number (without any leading digit(s) of +1 and/or 1).
2. If the 4-th digit of the dialed number (after the area code) is a non-zero number, do nothing. Otherwise, the regex filter will strip the leading 3 digits (area code) as well as the last 2 digits number and this will leave only 1-st 5-digits number (no area code). For instance, if the 10-digits dialed number is 0120123456, then the regex filter will return 01234. More examples followed:
10-digits input number output number --------------------- ------------- 4120123456 01234 0121234567 0121234567 1310156434 01564 8231234567 8231234567 0126543210 0126543210 Anyone? Thanks.
----- 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-tp5668666p5... Sent from the freeswitch-users mailing list archive at Nabble.com.
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
-- Sent from my mobile device
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-tp5668666p5... Sent from the freeswitch-users mailing list archive at Nabble.com.
mazilo wrote:
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.
"^(?:\d{3}(0\d{4})\d{2}|(\d{3}[1-9]\d{6}))$" Note that if the first value is captured, it will be in $1. The second captured value will be in $2. This is described at http://wiki.freeswitch.org/wiki/Regular_Expression mose
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@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-tp5668666p5... Sent from the freeswitch-users mailing list archive at Nabble.com.
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
Actually, I've just realised there is a way: ^(?|\d{3}(0\d{4})\d{2}$|^(\d{3}[1-9]\d{6}))$ The (?| ) bracket resets the numbering for each alternative, so the first set of brackets in each alternative both point to $1. -Steve On 25 October 2010 09:00, Steven Ayre <steveayre@gmail.com> wrote:
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@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-tp5668666p5... Sent from the freeswitch-users mailing list archive at Nabble.com.
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
Steven Ayre wrote:
Actually, I've just realised there is a way:
^(?|\d{3}(0\d{4})\d{2}$|^(\d{3}[1-9]\d{6}))$
The (?| ) bracket resets the numbering for each alternative, so the first set of brackets in each alternative both point to $1.
-Steve
Steve: Thank you and that does the trick. I try to modify the above regex filters so that it will become more user friendly using this expression="^(?|\d{3}(0\d{4})\d+|^(\d{3}[1-9]\d{6}))$". This way, the 1st regex filter (in bold) will process when the 4th digit is zero and only will capture starting from the 4th to 8th digits (a total of 5 digits) and will ignore the rest digits. In other words, if a user dials 12301234 or 1230123456 or 123012345 or 1230123456789, the regex filter will only return 01234. This works to a point, except if the entered number has an exact area code + 0 + 4 digits. For instance, 10-digits input number output number Comments --------------------- ------------- ---------- 4120123456 01234 Does work 41201234 Doesn't work 412012346 01234 Does work 0121234567 0121234567 Does work 1310156434 01564 Does work 131015643 01564 Does work 13101564 Doesn't work 8231234567 8231234567 Does work 823123456 823123456 Does work 0126543210 0126543210 Does work I can easily fix the above problem by introducing an additional regex filter into the above expression, i.e. expression="^(?|\d{3}(0\d{4})|\d{3}(0\d{4})\d+|^(\d{3}[1-9]\d{6}))$". However, if there is a better way to achieve this with less regex filter, it sure will be a plus. Mose: Thank you too even though the ":" doesn't seem to work. However, this bring an interesting thing for me to read the wiki http://wiki.freeswitch.org/wiki/Regular_Expression ReGex so that I will understand further. ----- 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-tp5668666p5... Sent from the freeswitch-users mailing list archive at Nabble.com.
I've gotta ask. What is the reason / business process you are doing that requires a complex regex/match like this? On Mon, Oct 25, 2010 at 9:18 AM, mazilo <Nabble@slickdeals.endjunk.com>wrote:
Steve: Thank you and that does the trick. I try to modify the above regex filters so that it will become more user friendly using this expression="^(?|\d{3}(0\d{4})\d+|^(\d{3}[1-9]\d{6}))$". This way, the 1st regex filter (in bold) will process when the 4th digit is zero and only will capture starting from the 4th to 8th digits (a total of 5 digits) and will ignore the rest digits. In other words, if a user dials 12301234 or 1230123456 or 123012345 or 1230123456789, the regex filter will only return 01234. This works to a point, except if the entered number has an exact area code + 0 + 4 digits. For instance,
10-digits input number output number Comments --------------------- ------------- ---------- 4120123456 01234 Does work 41201234 Doesn't work 412012346 01234 Does work 0121234567 0121234567 Does work 1310156434 01564 Does work 131015643 01564 Does work 13101564 Doesn't work 8231234567 8231234567 Does work 823123456 823123456 Does work 0126543210 0126543210 Does work
I can easily fix the above problem by introducing an additional regex filter into the above expression, i.e. expression="^(?|\d{3}(0\d{4})|\d{3}(0\d{4})\d+|^(\d{3}[1-9]\d{6}))$". However, if there is a better way to achieve this with less regex filter, it sure will be a plus.
Mose: Thank you too even though the ":" doesn't seem to work. However, this bring an interesting thing for me to read the wiki http://wiki.freeswitch.org/wiki/Regular_Expression ReGex so that I will understand further.
----- don't and stop are the ONLY two 4-letter words considered offensive to men, but not when used together.
-- -Rupa
Rupa Schomaker wrote:
I've gotta ask. What is the reason / business process you are doing that requires a complex regex/match like this?
Some VoSPs have their internal (non-NANPA standard) numbers with no area codes and of length less than 7 digits while my users are used to with a 10-digits dialing scheme. So, I thought perhaps if I device a scheme to let the users dial any 10-digits number and when the 1st digit is 0 (after any area code), then the dialplan will strip off the area code + the rest of unused digits and will only leave a 5-digits numbers starting with 0. I hope this makes it clear to you even though the logic behind this may not make sense. Thanks for asking. ----- 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-tp5668666p5... Sent from the freeswitch-users mailing list archive at Nabble.com.
mazilo <Nabble@slickdeals.endjunk.com> said:
Mose: Thank you too even though the ":" doesn't seem to work.
(?: is only for grouping and does not capture any values. -- Russell Mosemann ________________________________________________________ Concordia University, Nebraska See http://www.cune.edu/ for the latest news and events!
On Sun, Oct 24, 2010 at 11:09 PM, mazilo <Nabble@slickdeals.endjunk.com>wrote:
I am not much of a regex person but am looking for some help on crafting a simple regex filter that can do the following criterias:
1. The dialed number is always a 10-digits number, i.e. an area code + 7-digits number (without any leading digit(s) of +1 and/or 1).
2. If the 4-th digit of the dialed number (after the area code) is a non-zero number, do nothing. Otherwise, the regex filter will strip the leading 3 digits (area code) as well as the last 2 digits number and this will leave only 1-st 5-digits number (no area code). For instance, if the 10-digits dialed number is 0120123456, then the regex filter will return 01234. More examples followed:
10-digits input number output number --------------------- ------------- 4120123456 01234 0121234567 0121234567 1310156434 01564 8231234567 8231234567 0126543210 0126543210 Anyone? Thanks.
i'd say, this one: <action application="set" data="myNUM=${cond(${destination_number:4:1} == 0 ? ${regex(${destination_number}|\d{3}(0\d{4}).*|%1)} : ${destination_number})}"/> i wrote it by hearth .. so you might tune it a bit ... but the basic is here :)
On Mon, Oct 25, 2010 at 1:17 PM, Tihomir Culjaga <tculjaga@gmail.com> wrote:
On Sun, Oct 24, 2010 at 11:09 PM, mazilo <Nabble@slickdeals.endjunk.com>wrote:
I am not much of a regex person but am looking for some help on crafting a simple regex filter that can do the following criterias:
1. The dialed number is always a 10-digits number, i.e. an area code + 7-digits number (without any leading digit(s) of +1 and/or 1).
2. If the 4-th digit of the dialed number (after the area code) is a non-zero number, do nothing. Otherwise, the regex filter will strip the leading 3 digits (area code) as well as the last 2 digits number and this will leave only 1-st 5-digits number (no area code). For instance, if the 10-digits dialed number is 0120123456, then the regex filter will return 01234. More examples followed:
10-digits input number output number --------------------- ------------- 4120123456 01234 0121234567 0121234567 1310156434 01564 8231234567 8231234567 0126543210 0126543210 Anyone? Thanks.
i'd say, this one:
<action application="set" data="myNUM=${cond(${destination_number:4:1} == 0 ? ${regex(${destination_number}|\d{3}(0\d{4}).*|%1)} : ${destination_number})}"/>
i wrote it by hearth .. so you might tune it a bit ... but the basic is here :)
actualy it should work simply by this as well: <action application="set" data="myNUM=${regex(${destination_number}|\d{3}(0\d{4}).*|%1)}"/> if rexexp match fails, the api returns the source string without any changes. chers!
participants (7)
-
mazilo
-
Nyamul Hassan
-
Rupa Schomaker
-
Russell Mosemann
-
Russell.Mosemann@cune.org
-
Steven Ayre
-
Tihomir Culjaga