How do I swap phrases using regex

I have a documet that I have the following phrases:

Form “Video Adjustments”

Form “Users”

Form “Audio Settings”

…and I have to swap the terms with form:

“Video Adjustments” Form

“Users” Form

“Audio Settings” Form

I can find the phrase with the following form:

Form “*”

or

Form\s"*"

But when I try to put in the replacement:

“*” Form

It only puts “*” Form, but of course does not have the original phrase.

How do I put in the proper terms for Search and replace?

Thanks…

Chuck D.

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 … .

Keme:

At first it didn’t work but I am using:

Search - (Form) (".*")
Replace - $2 $1

Which works fine, as I have some terms not in the beginning.

Thank you for your wisdom, very much appreciated…