for regex - is it possible to move a word from the beginning of the line to the end of the line?
everyone. is it possible to move a word from the beginning of the line to the end of the line, and the one from the end to be place at the beginning of the line? It’s a change of places, viceversa
Paul is at home with his brother John.
John is at home with his brother Paul.
can this be done with regex?
I try this regex, but not a great solution:
(^\w+)- select the first word on the beginning of each line
(\w*$)- select the last word at the end of the line
This seems to work for your data, but there’s probably more to what you really need:
replace with :
thank you all. Of course, in the end I find myself a solution:
Hello, @robin-cruise, and All,
I suppose that, if the sentence contains a single word, followed with a full stop like
Paul., it should not be concerned by the replacement, ins’t it ?
So, the correct regex S/R is :
\bassertions ensure that the group
3contain true words, i.e. the first and last character of group
2are non-word characters
2we just can use a greedy quantifier
+?) as we’re looking for the last word of current line, anyway !
As the search regex contains three expressions with the
+quantifier, this means that each group is not empty. And, in case of the minimal sentence
Paul John., the group
2is just the
spacechar between the two firstnames !