我必须编写一些模式,这些模式将在用户输入时通过Regex用于匹配目的:
string pattern = "^.*overview\ of\ sales.*customer\ information.*$";
string input = "overview of sales with customer information";
Run Code Online (Sandbox Code Playgroud)
有没有办法删除正则表达式中的单词顺序?所以
string pattern = "^.*overview\ of\ sales.*customer\ information.*$";
Run Code Online (Sandbox Code Playgroud)
也会匹配:
string input = "customer information with overview of sales";
Run Code Online (Sandbox Code Playgroud)
这可以通过以相反的顺序编写每个模式来完成,但是因为模式的数量很少并且将随着时间和数量*而增长.这往往是繁琐的做法,所以请指导这件事.
我正在尝试将表中的模式与用户话语进行匹配。
string userUtterance = "I want identification number for number of customers";
string pattern1 = "identification number";
string pattern2 = "tom";
string pattern3 = "id";
Run Code Online (Sandbox Code Playgroud)
预期结果:
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
Run Code Online (Sandbox Code Playgroud)
我想就如何使用匹配该语法的正则表达式来限制不明确的匹配和精确匹配字面词提供一些建议。
谢谢
我需要根据连接词,即on,in,from等在数组中拆分几个字符串.
string sampleString = "what was total sales for pencils from Japan in 1999";
Run Code Online (Sandbox Code Playgroud)
期望的结果:
what was total sales
for pencils
from japan
in 1999
Run Code Online (Sandbox Code Playgroud)
我熟悉基于一个单词而不是多个单词同时拆分字符串:
string[] stringArray = sampleString.Split(new string[] {"of"}, StringSplitOptions.None);
Run Code Online (Sandbox Code Playgroud)
有什么建议?