fast regex matching implementation