Skip to content

Instantly share code, notes, and snippets.

@thehashrocket
Last active January 4, 2017 13:38
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 thehashrocket/ef617f29458fc668da69e89629c89f38 to your computer and use it in GitHub Desktop.
Save thehashrocket/ef617f29458fc668da69e89629c89f38 to your computer and use it in GitHub Desktop.
string = "<token>important text</token> other stuff <token>more important text</token>"
matches = string.to_enum(:scan, /\<token\>(.*?)\<\token\>/).map { Regexp.last_match }
#=> [<#Match 1:>, <#Match 1:>]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment