Last active
August 29, 2015 14:10
-
-
Save tyre/ed013c3c7b56b5a25a5c to your computer and use it in GitHub Desktop.
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
url = "https://google.com/:bubbles/frosted" | |
# We want "/:bubbles/" to match, but not "/:bubbles_waffle/" to match | |
regex = ~r/(\/|\a)\:bubbles(\/|\Z)/ | |
# Sad Times! | |
# Expect ":bubbles" to be replaced with "33" | |
String.replace url, regex, "\\133\\2" | |
# => "https://google.com/frosted" | |
# Works! | |
# Expect ":bubbles" to be replaced with " 33 " | |
String.replace url, regex, "\\1 33 \\2" | |
# => "https://google.com/ 33 /frosted" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment