Last active
March 23, 2020 21:18
-
-
Save havenwood/e6360abf7c7fbafb615ecb6ffb8057de to your computer and use it in GitHub Desktop.
This file contains 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
string = 'numbers: one two three # en fin' | |
caption = string[/\A\w*/] | |
content = string[/(?<=:).*(?=#)/].split | |
caption | |
#=> "numbers" | |
content | |
#=> ["one", "two", "three"] | |
# or | |
caption, content = string.partition(/:\s*/).then { [_1, _3[/.*(?=#)/].split] } | |
caption | |
#=> "numbers" | |
content | |
#=> ["one", "two", "three"] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment