Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active March 23, 2020 21:18
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 havenwood/e6360abf7c7fbafb615ecb6ffb8057de to your computer and use it in GitHub Desktop.
Save havenwood/e6360abf7c7fbafb615ecb6ffb8057de to your computer and use it in GitHub Desktop.
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