str = "I breathe when I sleep"
# Numbered matches...
r1 = /I (\w+) when I (\w+)/
s1 = str.sub(r1,'I \2 when I \1')
# Named matches...
r1 = /I (?<verb1>\w+) when I (?<verb2>\w+)/
s2 = str.sub(r2,'I \k<verb2> when I \k<verb1>')
puts s1     # I sleep when I breathe
puts s2     # I sleep when I breathe

