Algorithm 针对多种模式进行有效字符串匹配的数据结构

Algorithm 针对多种模式进行有效字符串匹配的数据结构,algorithm,language-agnostic,pattern-matching,string-matching,trie,Algorithm,Language Agnostic,Pattern Matching,String Matching,Trie,我正在寻找一个有效的数据结构,允许字符串到模式匹配。这些模式遵循类似正则表达式的语法,但允许递归。它们包含选项、选项和递归/通配符。模式的一些示例包括: how many * (are coming|came) to (the)? party (drunk|sober)? people annoying * 这些模式将匹配以下字符串: how many drunk people are coming to the party how many people came to party how

我正在寻找一个有效的数据结构,允许字符串到模式匹配。这些模式遵循类似正则表达式的语法,但允许递归。它们包含选项、选项和递归/通配符。模式的一些示例包括:

how many * (are coming|came) to (the)? party
(drunk|sober)? people
annoying *
这些模式将匹配以下字符串:

how many drunk people are coming to the party
how many people came to party
how many annoying drunk people are coming to the party
对于那些人来说,这将是失败的:

how many are coming to the party  <-- expected something else after 'many'
drunk sober people  <-- has to be either 'drunk' or 'sober' but not both

有多少人来参加聚会,这看起来像是一个特殊情况。不幸的是,您的定义没有将其进一步限制为,因为可能存在歧义。所以,你最好的选择是,或者,据我所知,

你检查过了吗?考虑建立一个有限状态机:@ Juvia:是的,但是这些算法是为了精确的字符串匹配。“JimMISCHEL状态机是一个选项,但是我在寻找更具体的东西。我看到了递归。”但是没有看到任何例子。非常感谢你的链接!我一定会看一看他们。我看了看消息来源,我有两个顾虑。首先,语法的大小将是巨大的,而且算法似乎只是试图一个接一个地匹配一个模式(这是我想要避免的)。其次,看起来您无法在运行时向语法中添加其他规则。但我很确定我能以某种方式实现这一点。