5. Reverse reference of regular expressions
Like Perl, Ruby's natural support for regular expressions is their advantage. Friends who know Perl can see that Ruby's regular expressions are exactly the same as Perl in many places.
Backreference refers to a pattern enclosed in parentheses in a regular expression. The pattern on the following two lines is the same, but the second sentence adopts the form of backreference.
pat1 = /([\d\w])-([\d\w])/ pat2 = /([\d\w])-\1/
pat1 = /([\d\w])-(\1)0/ pat2 = /([\d\w])-\10/ # 0 print pat1 =~ "1-10" # nil print pat2 =~ "1-10"