Suppose I have a string like "abc | xyz" and I'd like to turn it into "xyz | abc" using only a regular expression substitution. (For this example there may be better ways, but this is a stand-in for something hairier.)
The following code doesn't do what I expect:
x = "abc | xyz"
x = x.gsub(/^([^\|\s]*)\s*\|\s*(\S*)/, "\2 | \1")
puts x
Is it obvious what I'm doing wrong? Thanks!