Skip to content

Instantly share code, notes, and snippets.

@erubboli
Created October 22, 2010 09:38
Show Gist options
  • Save erubboli/640241 to your computer and use it in GitHub Desktop.
Save erubboli/640241 to your computer and use it in GitHub Desktop.
re = /(?<nome>[\S]+)\s(?<cognome>[\S]+)/
result = re.match "Enrico Rubboli"
#=> #<MatchData "Enrico Rubboli" nome:"Enrico" cognome:"Rubboli">
result[:nome]
#=> "Enrico"
"Enrico Rubboli".sub re, '\k<cognome> \k<nome>'
#=> "Rubboli Enrico"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment