s/^([^ ]+) +([^ ]+)/$2 $1/; # swap first two words
So i don't get, to begin with, the logic of the left side of the substitution... inside each of those brackets - what confuses me is the ^ - which I know, although only because I recently read it, that it's the same as \A, i.e. start of a string.
I want to know
(a) how the word characters are matched - i just see whitespace
(b) why the second item has a ^ as well - surely it's no longer "start of a string" by that point?
Help appreciated,
cheers,
Shams
so between the first pair of forward slashes, you have captured in group 1 the leading one or more consecutive non blank characters in the string, followed by one or more blanks, followed by a capturing group 2 containing one or more consecutive non blank characters.