Last active
August 29, 2015 14:14
-
-
Save ryancastro/89824fdc48c2e52cca6f to your computer and use it in GitHub Desktop.
Easy Ruby Regex - the shortest regex find, and replace methods in Ruby.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#index capture groups: | |
url = "https://gist.github.com/ryancastro/whatever.git" | |
p url[/(.*)\/whatever.git/, 1] | |
p url.gsub(/(.*)\/whatever.git/, '\1') | |
#named capture groups: | |
url = "https://gist.github.com/ryancastro/whatever.git" | |
p url[/(?<url>.*)\/whatever.git/, "url"] | |
p url.gsub(/(?<url>.*)\/whatever.git/, '\k<url>') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment