REGEX/Dialogflow/format实体

2024-03-29 00:02:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我的目标是在Dialogflow中创建一个名为“Order ID”的实体

我希望dialogflow能够理解/返回此订单ID的参考值,无论用户输入的是正确的还是错误的。你知道吗

正确示例:123-1234567-1234567
错误示例:12345671234567
错误示例:我的订单是12345671234567

我可以用dialogflow中的RegEx实现这一点吗?你知道吗


Tags: 用户订单实体id示例目标错误order
3条回答

您可以使用DialogFlow功能。它为实体提供regex。你知道吗

enter image description here

更多信息,请查看official document

import re

arrs = [
    '1231234567-1234567',
    '123-12345671234567',
    '-123-1234567-1234567',
    '12312345671234567',
    '123-1234567-1234567',
]

for t in arrs:
    print(t,' =>',end=' ')
    if re.match(r'\d{3}\-\d{7}\-\d{7}',t):
        print('Correct')
    else:
        print('Something is wrong!')

结果:

1231234567-1234567  => Something is wrong!
123-12345671234567  => Something is wrong!
-123-1234567-1234567  => Something is wrong!
12312345671234567  => Something is wrong!
123-1234567-1234567  => Correct

您可以使用这个regex \A([1-9]{3}-[1-9]{7}-[1-9]{7})\z。Dialogflow使用re2正则表达式格式。您可以访问https://github.com/google/re2/wiki/Syntax作为参考。你知道吗

相关问题 更多 >