正则表达式的分组
在模式内部,\1序列指的是第一个组的匹配,\2序列指的是第二个组的匹配,如
irb(main):008:0> "12:50am"=~/(\d\d):(\d\d)(..)/
=> 0
irb(main):009:0> "Hour is #$1,minute is #$2"
=> "Hour is 12,minute is 50"
irb(main):010:0> "12:50am"=~/((\d\d):(\d\d))(..)/
=> 0
irb(main):011:0> "Time is #$1"
=> "Time is 12:50"
irb(main):012:0> "Hour is #$2,minute is #$3"
=> "Hour is 12,minute is 50"
irb(main):013:0> "AM/PM is #$4"
=> "AM/PM is am"
irb(main):014:0>