Posted By

obi on 08/21/09


Tagged


Versions (?)

capturing regex matches


 / Published in: Ruby
 

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

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

  1. str = "Q1-1947"
  2. str =~ /Q(\d)-(\d{4})/
  3.  
  4. # prints "1"
  5. puts $1
  6.  
  7. # prints "1947"
  8. puts $2

Report this snippet  

You need to login to post a comment.