[Freeswitch-users] regular expression ?

Michael Collins msc at freeswitch.org
Mon Jun 4 00:33:46 MSD 2012


If you are trying to match the dialed digits "*999*11#" then yes, the
pattern you suggested below is not appropriate. Just putting special
characters inside of [ and ] is not enough to change their meaning. The
proper way to handle this is by doing what Covici suggested and use a \
(backslash) in front of the * characters. (The # char is not one of the
special characters in PCRE, therefore it does not need a backslash.)

The best pattern for your example is:

^(\*999\*11#)$

That would match "*999*11#" and absolutely nothing else. If you need to be
flexible on the digits that you match you could do something like this:

^(\*\d\d\d\*\d\d#)$

That would match * plus 3 digits plus * plus 2 digits. Example matches:
*123*45#
*876*99#
*333*33#

You could even grab the internal digit sequences and put them into $2 and
$3:

^(\*(\d\d\d)\*(\d\d)#)$

Notice what the special vars contain by using this little table:

Dialed:   $1:       $2:     $3:
*123*45#    *123*45#  123     45
*876*99#    *876*99#  876     99
*333*33#    *333*33#  333     33

I strongly recommend that you try it out. Put this in your dialplan and try
it out:

<extension name="tinkering with regexes">
  <condition field="destination_number"
expression="^(\*(\d\d\d)\*(\d\d)#)$">
      <action application="log" data="INFO \$1 is $1"/>
      <action application="log" data="INFO \$2 is $2"/>
      <action application="log" data="INFO \$3 is $3"/>
  </condition>
</extension>

Try it out - make a bunch of calls and see what happens. Change the regex
around and try dialing again. I promise you that once you start writing
your own regexes - and occasionally breaking them in the process - you will
learn them and use them to your advantage.

-MC

On Sat, Jun 2, 2012 at 3:11 AM, Samira Mh <saami_mh at ymail.com> wrote:

> thanks so much for your reply,nut i think the below patter is true as
> well,
> ^([*]999[*]11[#])$
> is that true?
>
>
>   ------------------------------
> *From:* "covici at ccs.covici.com" <covici at ccs.covici.com>
> *To:* FreeSWITCH Users Help <freeswitch-users at lists.freeswitch.org>
> *Sent:* Saturday, June 2, 2012 2:18 PM
> *Subject:* Re: [Freeswitch-users] regular expression ?
>
> Just put a \ before each * and maybe the # as well and you should be
> good to go.
>
> Samira Mh <saami_mh at ymail.com> wrote:
>
> > hi guys,
> > it possible to match *999*11# in regular expression in freeswitch ?
> > in the wiki the above example don't exis,
> > plz help thanks
> > ----------------------------------------------------
> > Alternatives:
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120603/489e93a3/attachment.html 


Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list