【发布时间】:2015-08-02 18:14:11
【问题描述】:
我想知道是否有任何正则表达式匹配如下:
(我在示例中使用了 ruby。)
"nowhere".scan(/<some regex>/) #=> ["no", "now", "where", "here"]
【问题讨论】:
-
ere,re,e 怎么样?
-
您需要一个算法来枚举所有可能的子字符串并检查它是否在您的已知单词字典中。喜欢
dict = %w[no now where here her]; matches = []; s = "nowhere"; (1..s.size).each do |l| s.chars.each_cons(l) do |sub| matches << sub.join if dict.include? sub.join end end; matches。或者反过来做,在字符串中搜索字典中的每个单词。