我必须编写一些模式,这些模式将在用户输入时通过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)
这可以通过以相反的顺序编写每个模式来完成,但是因为模式的数量很少并且将随着时间和数量*而增长.这往往是繁琐的做法,所以请指导这件事.
Tay*_* Hx 12
你会想要使用积极的前瞻性 ?=.*.
[正向前瞻]
q(?=u)匹配后跟au的aq,而不使u成为匹配的一部分.积极的先行构造是一对括号,左括号后跟一个问号和一个等号.
在这种情况下可以使用正向前瞻来匹配任何顺序的一组模式,如下所示:
(?=.*customer)(?=.*information)(?=.*with)(?=.*overview)(?=.*of)(?=.*sales)

要修改,只需根据需要添加,编辑或删除单词.
编辑
在这里找到了解释相同概念的问题:https://stackoverflow.com/a/3533526/2081889