/(fred|wilma) (flintstone) \2/ # match "fred" or "wilma" and put them in bucket 1 # followed by "flintstone" and put that in bucket 2 # then match whatever is in bucket 2. Which in this # case must be "flintstone" so the regex is # equivelent to # /(fred|wilma) (flintstone) flintsone/ /(fred|wilma) (flintstone) \1/ # match "fred" or "wilma" and put them in bucket 1 # followed by "flintstone" and put that in bucket 2 # then match whatever is in bucket 1. Which in this # case could be "fred" or "wilma" so the regex is # equivelent to one of the following: # /(fred) (flintstone) fred/ # /(wilma) (flintstone) wilma/