in reply to Re^2: How do I reverse the order of the first and last word of a string?
in thread How do I reverse the order of the first and last word of a string?
If you try
you'll see that you'll have some trouble with greediness of the middle match: the "last word" will match too little: I expect it to match just the last letter.s/(\w+)(.*)(\w+)/$3$2$1/
is the other extreme, and you'll match too little.s/(\w+)(.*?)(\w+)/$3$2$1/
I can think of two solutions:
ors/(\w+)(.*?)(\w+)$/$3$2$1/
s/(\w+)(.*?)(\w+)(\W*)$/$3$2$1$4/
s/(\w+)(.*)\b(\w+)$/$3$2$1/
|
|---|