To reference partial matches in a regular expression, you need to first mark a section to match by enclosing it in parentheses. Each parenthesis group will then be numbered in sequence, and you reference it by $<number>.
Also, in regular expressions, the asterisk is not the “any number of any character” wildcard, but rather “any number of the preceding character”. The token for “any character” is a period.
Hence, wildcard *
(as used by default in MS Word) translates to regex .*
.
Try this:
- Search for
(Form) (".*")
- Replace with
$2 $1
If the phrase requiring rearrangement always constitutes a full paragraph, you may benefit from some additional code to avoid matches in running text.
- Search for
^(Form) (".*")[:space:]*$
- Replace with
$2 $1\n
The leading ^
in the search term means “match only from start of new paragraph”, and [:space:]*
allows for trailing space(s) (but nothing else) before $
dictates “match to end of paragraph”. The trailing space matcher is outside parentheses, so the replace will discard them.
This will catch the examples you have given, occurring as solitary items on a line, but will avoid altering running text with constructs such as … sometimes we may encounter form “misbehavior” in our project … .