Skip to content

Instantly share code, notes, and snippets.

@webmat
Created December 4, 2008 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webmat/32138 to your computer and use it in GitHub Desktop.
Save webmat/32138 to your computer and use it in GitHub Desktop.
class String
# Return everything after the given string
# or nil if the substring can't be found
def after(prefix)
match = self.match Regexp.new(Regexp.escape(prefix) + "(.*)")
match && match[1]
end
end
dir = "/Users/mat/Desktop/wordpress-1"
#=> "/Users/mat/Desktop/wordpress-1"
file = "/Users/mat/Desktop/wordpress-1/wp-trackback.php"
#=> "/Users/mat/Desktop/wordpress-1/wp-trackback.php"
file.after dir
#=> "/wp-trackback.php"
file.after "uhh"
#=> nil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment