Skip to content

Instantly share code, notes, and snippets.

@thinkcreate
Created May 31, 2010 09:17
Show Gist options
  • Save thinkcreate/419681 to your computer and use it in GitHub Desktop.
Save thinkcreate/419681 to your computer and use it in GitHub Desktop.
class Regexp
def self.from_glob(glob)
Regexp.new(['^',Regexp.escape(glob).gsub('\\*','(.*)').\
gsub('\\\(.*)','\*').\
gsub('\\[','([').\
gsub('\\]','])').\
gsub('\\?','(.)'),'$'].join)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment