How to insert space characters into the middle of a string using Replace in Word

2 years ago 256

Microsoft Word's Replace diagnostic is under-used due to the fact that the much analyzable the requirement, the much analyzable the solution. If you're inserting characters into the mediate of a string, determination is simply a solution.

man typing connected  computer

Image: istock/BongkarnThanyakij

Some Microsoft Word users ne'er advancement beyond the simplest find-and-replace tasks due to the fact that they don't cognize astir wildcards oregon they find them hard to apply. I admit that sometimes the solution remains a enigma to maine until I permission the machine to tally the vacuum oregon execute immoderate different menial task, which seems to wide my caput truthful the reply tin emergence to the surface. 

SEE: 83 Excel tips each idiosyncratic should master (TechRepublic)

Knowing however the wildcards enactment isn't enough; you indispensable beryllium alert of however the 2 hunt strings, find and replace, subordinate to 1 another. In this article, I'll amusement you a regenerate task that uses wildcards to insert a abstraction successful the mediate of 3 characters. How they subordinate to each different is indispensable to succeed. 

I'm utilizing Microsoft 365 connected a Windows 10 64-bit system, but you tin usage earlier versions. Word Online doesn't enactment wildcards. For you convenience, you tin download the objection .docx and .doc files, but the hunt strings are simple, and you tin easy make the papers yourself by referring to Figure A

The problem

Let's accidental you person respective strings wherever the lone narration is that the archetypal 2 characters are ever the same—let's usage a and b. What follows ab volition often beryllium different: abc, ab8, abf and truthful on. The characters pursuing the archetypal 2 are inconsistent successful benignant but the strings volition ever beryllium 3 characters, arsenic shown successful Figure A. You privation to clasp each of the characters but insert a abstraction aft b, successful each instance.

Figure A

wordreplace-a.jpg

  Let's insert a abstraction aft b, successful each lawsuit wherever ab is the archetypal 2 characters successful a three-letter string.

In Excel, you mightiness effort a drawstring relation oregon adjacent Text to Columns, but those features aren't disposable successful Word. Your archetypal inclination is astir apt Replace, and that's wherever I would start. 

Unless you're precise acquainted with this feature, you mightiness effort a fewer things that won't enactment specified arsenic ab?, which works OK for uncovering the archetypal 3 characters successful strings that statesman with ab, but however bash you clasp the ? quality successful the regenerate string? If you effort ab ?, you'll find that it doesn't enactment arsenic expected! It returns, ab ?; it doesn't clasp the existent 3rd quality successful the string. You mightiness effort respective antithetic sets of find-and-replace strings that astir get you there. The reply is simply a fewer wildcards and is astir apt easier than you mightiness think.

SEE: Windows 10: Lists of vocal commands for code designation and dictation (free PDF) (TechRepublic)

How to usage the wildcards successful Word

As hinted at, wildcards are the answer, but getting conscionable the close ones successful some the find-and-replace hunt strings takes a spot of thought (unless you're a wildcard expert). Let's interruption it down by each wildcard character.

First, the ? quality volition find immoderate azygous character, truthful ab? does what you expect. The occupation is, you can't easy explicit the replacement string, not arsenic is. That solution is to specify a scope utilizing the () characters truthful Replace knows which quality to transcript to the replacement string, aft inserting the space:

ab(?)

This gets america person due to the fact that the scope (?) is referred to successful the regenerate drawstring by position. In this case, it's the archetypal position, truthful you extremity up with

find: ab(?)

replace: ab \1

The regenerate drawstring includes a abstraction betwixt ab and \1, but what does \1 mean? That's a notation to the portion (?) successful the find string. Simply put, the \ quality references a scope and the fig 1 tells Word which range. In this case, there's lone one. Word copies the quality successful parentheses to the replacement string. These 2 get america astir there, truthful let's tally them and spot what happens:

  1. Press Ctrl + H to unfastened the Replace dialog.
  2. Delete immoderate erstwhile find-and-replace strings.
  3. In the Find What control, participate ab(?).
  4. In the Replace With control, participate ab \1. Remember that there's a abstraction betwixt ab and \1.
  5. If necessary, click the More fastener and past cheque the Use Wildcards enactment and the No Formatting enactment if it isn't dimmed (to region formatting applied successful the erstwhile regenerate task).
  6. Click Replace All (Figure B).  
  7. Close the dialog.

Figure B

wordreplace-b.jpg

  The find drawstring matched the drawstring 'about.'

As you tin spot successful Figure B, the find-and-replace strings worked perfectly until they encountered the connection 'about.' That's due to the fact that the (?) constituent does lucifer a azygous character, but it doesn't lucifer lone 1 quality due to the fact that it's portion of a range. Consequently, it doesn't trim the find drawstring to lone 3 characters.

The bully quality is that we genuinely are astir there. Before continuing, property Ctrl + Z to undo each the changes the erstwhile regenerate task made. Then, repetition the instructions above, skipping measurement 2—you don't privation to delete what you already have. In measurement 3, participate > to the extremity of the string: ab(?)>. The > quality denotes the extremity of the search. Adding this quality volition unit Word to halt matching with the 3rd character.

As you tin spot successful Figure C, the hunt works arsenic expected, changing the archetypal 3 strings and leaving the connection "about" intact. 

Figure C

wordreplace-c.jpg

This clip the 2 strings enactment unneurotic to instrumentality the expected results. 

Are you wondering wherefore Word ignores ABC, Inc.? Checking the Use Wildcards enactment takes attraction of that drawstring automatically due to the fact that wildcard searches are lawsuit sensitive.

We utilized lone a fewer wildcards—(), ?, and \—to get the occupation done. Knowing what wildcards bash and however they enactment unneurotic is cardinal to success. 

Microsoft Weekly Newsletter

Be your company's Microsoft insider by speechmaking these Windows and Office tips, tricks, and cheat sheets. Delivered Mondays and Wednesdays

Sign up today

Also see

Read Entire Article