fork download
  1. (defn tails [s]
  2. (take (count s) (reductions (fn [s _] (rest s)) s s)))
  3.  
  4. (defn match[p s]
  5. (cond
  6. (empty? p) (empty? s)
  7. (empty? s) false
  8. :else
  9. (case (first p)
  10. \* (boolean (some (partial match (rest p)) (tails s)))
  11. \? (recur (rest p) (rest s))
  12. \\ (and (= (ffirst p) (first s))
  13. (recur (drop 2 p) (rest s)))
  14. (and (= (first p) (first s))
  15. (recur (rest p) (rest s))))))
  16.  
  17. (println (time (match "as*d*?qwe*qwe" "as123dssqwe12345678qwe")))
  18. (println (time (match "as*d*?qwe*qw" "as123dssqwe12345678qwe")))
Success #stdin #stdout 1.66s 335552KB
stdin
Standard input is empty
stdout
"Elapsed time: 1.331461 msecs"
true
"Elapsed time: 0.656603 msecs"
false