regex 星号应用程序拨号计划中的模式匹配

moiiocjp  于 2023-03-09  发布在  其他
关注(0)|答案(3)|浏览(247)

我需要为星号模式SIP呼叫这样的方式。
1.模式仅包含“*"、"#”和0-9位数字
1.模式的第一个参数对于“+”符号是可选的。
好像和

*1203#023212232
+*1203#122
12345555

但是拒绝这些案例

3434+23443
*2334%2323

我是这样准备的

exten => _[*|#|+|0-9].,1,Answer()

但这也是接受以下模式太多,我不想匹配。

*2334%2323
zlwx9yxi

zlwx9yxi1#

    • TL;医生**

您可以使用REGEX function

    • 更多详细信息**
  • 查看REGEX函数文档 *

在星号cli上键入"core show function REGEX":

asthost*CLI> core show function REGEX

  -= Info about function 'REGEX' =-

[Synopsis]
Check string against a regular expression.

[Description]
Return '1' on regular expression match or '0' otherwise
Please note that the space following the double quotes separating the regex
from the data is optional and if present, is skipped. If a space is desired at
the beginning of the data, then put two spaces there; the second will not be
skipped.

[Syntax]
REGEX("regular expression" string)

[Arguments]
Not available

[See Also]
Not available
  • 编写您的拨号计划 *

扩展名. conf文件:

[default]
exten  => _[*#+0-9].,1,Set(match=${REGEX("^\\+?[0-9#*]+$" ${EXTEN})})
same   =>            n,GotoIf($["${match}" = "1"]?proceed:endcall)
same   =>            n(proceed),Answer()
same   =>            n(endcall),Hangup()
  • 重新加载您的拨号计划 *

在星号cli上键入"拨号计划重新加载":

asthost*CLI> dialplan reload
  • 检查您的拨号计划 *

在星号cli上键入"拨号计划显示默认值":

asthost*CLI> dialplan show default
[ Context 'default' created by 'pbx_config' ]
  '_[*#+0-9].' =>   1. Set(match=${REGEX("^\\+?[0-9#*]+$" ${EXTEN})}) [extensions.conf:7]
                    2. GotoIf($["${match}" = "1"]?proceed:endcall) [extensions.conf:8]
     [proceed]      3. Answer()                                   [extensions.conf:9]
     [endcall]      4. Hangup()                                   [extensions.conf:10]

-= 1 extension (4 priorities) in 1 context. =-
  • 测试您的拨号计划 *

从您的SIP端点开始呼叫,即通过Local-Channel发起呼叫。不要忘记将详细级别设置为3,这样您就可以看到拨号计划输出。

asthost*CLI> core set verbose 3
Console verbose was OFF and is now 3.
asthost*CLI> channel originate Local/*1203#023212232@default application Hangup
    -- Called *1203#023212232@default
    -- Executing [*1203#023212232@default:1] Set("Local/*1203#023212232@default-00000019;2", "match=1") in new stack
    -- Executing [*1203#023212232@default:2] GotoIf("Local/*1203#023212232@default-00000019;2", "1?proceed:endcall") in new stack
    -- Goto (default,*1203#023212232,3)
    -- Executing [*1203#023212232@default:3] Answer("Local/*1203#023212232@default-00000019;2", "") in new stack
    -- Local/*1203#023212232@default-00000019;1 answered
  == Spawn extension (default, *1203#023212232, 3) exited non-zero on 'Local/*1203#023212232@default-00000019;2'
bqjvbblv

bqjvbblv2#

我不认为星号支持regex表达式中这么大的灵活性。
实现这一点的最佳方法是,将此扩展变量传递给AGI,并在那里进行正则表达式匹配。

exten => _.,1,AGI(Your AGI SCRIPT,${EXTEN})  // Pass the extension number to your Agi script.If that match your requirement set an agi variable **match** to 1 

     exten => s,n,GotoIf($["${match}" = "1"]?proceed:endcall) //Check the match variable status and proceed based on that 

     exten => s,n(proceed),Answer()
     exten => s,n(endcall),Hangup()

这只是实现您的要求的一个选项

xriantvc

xriantvc3#

不如这样:

\+?[0-9#*]+

您可能需要锚定它:

^\+?[0-9#*]+$

相关问题