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
您可以使用DialogFlow功能。它为实体提供regex。你知道吗
更多信息,请查看official document
结果:
您可以使用这个regex
\A([1-9]{3}-[1-9]{7}-[1-9]{7})\z
。Dialogflow使用re2正则表达式格式。您可以访问https://github.com/google/re2/wiki/Syntax作为参考。你知道吗相关问题 更多 >
编程相关推荐