\1 refers to the match of the first group : Regexps Group « Development « Ruby






\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" 

 








Related examples in the same category

1.An unescaped vertical bar(|) matches either the regular expression that precedes it or the regular expression that follows it.
2.use parentheses to group terms within a regular expression
3.unescape HTML
4.Backslash Sequences in the Substitution