gpt4 book ai didi

c# - 精确/文字单词或模式匹配正则表达式

转载 作者:太空宇宙 更新时间:2023-11-03 21:36:36 34 4
gpt4 key购买 nike

我正在尝试将表中的模式与用户话语 匹配。

string userUtterance = "I want identification number for number of customers";

string pattern1 = "identification number";

string pattern2 = "tom";

string pattern3 = "id";

期望的结果:

bool match1  =  regex.Ismatch(userUtterance, pattern1); // should match

if(match1 == true)
{
// replace only the matched pattern in userUtterance
};

bool match2 = regex.Ismatch(userUtterance, pattern2); // should not match

bool match3 = regex.Ismatch(userUtterance, pattern3); // should not match

我想就使用匹配该语法的正则表达式来限制歧义匹配和精确匹配字面词提出一些建议。

谢谢

最佳答案

您可以使用 anchor \b 作为单词边界:

"\bonly these words\b"

这将匹配这些句子中的仅这些词:

Here are only these words baby.

Here are "only these words" baby.

Here are only these words, baby.

Here are only these words.

I said: 'only these words'.

关于c# - 精确/文字单词或模式匹配正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21460888/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com