# [Freeswitch-users] Need help on regex

mazilo Nabble at slickdeals.endjunk.com
Mon Oct 25 07:18:05 PDT 2010

```
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-tp5668666p5670827.html
Sent from the freeswitch-users mailing list archive at Nabble.com.

```