matches :: String -> String -> Bool matches ('^':rs) = dm rs where cm r c = r == '.' || r == c dm (r:'*':rs) (c:cs) = (dm rs (c:cs)) || ((cm r c) && (dm (r:'*':rs) cs)) dm (_:'*':"") "" = True dm (r:rs) (c:cs) = cm r c && dm rs cs dm "" _ = True dm "$" "" = True dm _ _ = False matches rs = matches ("^.*" ++ rs)