capturing regex matches


/ Published in: Ruby
Save to your folder(s)

don't forget to include parentheses around the expressions you want to match


Copy this code and paste it in your HTML
  1. str = "Q1-1947"
  2. str =~ /Q(\d)-(\d{4})/
  3.  
  4. # prints "1"
  5. puts $1
  6.  
  7. # prints "1947"
  8. puts $2

URL: http://www.regular-expressions.info/ruby.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.