1

Is there a way to move an entire specific word at the beginning of the sentence it belongs to? Let's say I want words contained within brackets to be repositioned.

At the moment I have something like this:

  • WordOne wordtwo wordthree wordsfour [targetWord] otherWord otherword.

I would like it to become:

  • [targetWord] WordOne wordtwo wordthree wordsfour otherWord otherword.

I know how to identify the word within brackets, but I was wondering if there is a way to move it.

1

You can achieve this with a "marking subexpression", which are just () parenthesis where each set can be referenced later with $#.

So the below GREP finds three groups of characters, then rearranges them:

  • GREP Find: (.+ )(\[.+\])\s?(.*)

  • GREP Replace: $2 $1$3

The 1st group finds anything up to the bracketed text, the 2nd is your bracketed text, and the 3rd is any optional remaining text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.