Mega Code Archive

 
Categories / Ruby / Development
 

1 refers to the match of the first group

# \2 the second group,and so on. # Outside the pattern,the special variables $1, $2, and so on, serve the samepurpose.  "12:50am" =~ /(\d\d):(\d\d)(..)/ # 0  "Hour is #$1, minute #$2" # "Hour is 12, minute 50"  "12:50am" =~ /((\d\d):(\d\d))(..)/ # 0  "Time is #$1" # "Time is 12:50"  "Hour is #$2, minute #$3" # "Hour is 12, minute 50"  "AM/PM is #$4" # "AM/PM is am"