Posts Tagged ‘find and replace’

h1

Word: Find all upper case words within parentheses and change to lower case

March 6, 2022

One of my readers asked if there was a way to change upper case strings within parentheses to lower case. For example, (INHALED DEEPLY) to (inhaled deeply). It seems they had hundreds of them, so doing them one at a time wasn’t the most efficient use of their time.

I was able to come up with a wildcard find to identify them all, but I couldn’t come up with a replace that preserved the contents while changing the case. I fiddled around a bit trying to get a macro to work, but to no avail. Then I decided to ask my question on the Microsoft support forums, but before I did so, I did a quick search to see if an answer had already been given—and it had! (https://answers.microsoft.com/en-us/msoffice/forum/all/search-and-replace-uppercase-to-lowercase/b2ed6ffa-4fe7-450d-a66c-7578811ce71f)

NOTE: As always, test on a copy of your document before you run this—you are making a global change that may target more than you want. For example, these will all get changed to lower case:

  • upper case acronyms in parentheses
  • anything inside parentheses that starts with a capital letter, such as proper nouns, whether in all upper case or not
  • everything from the first upper case letter after an opening parenthesis to the first-found closing parenthesis, which might be some pages later if you forgot to close the parenthesis.

This is a brute force method and may have unintended consequences. If in doubt, click Find Next to check each instance before you make this global change. 

Steps to achieve this:

  1. Press Ctrl+h to open the Find and Replace window.
  2. Click the Find tab (this is important).
  3. In the Find What field, type \(([A-Z]*)\)
  4. Click More and select the Use wildcards checkbox.
  5. Click Find In and select Main Document from the drop-down list.
  6. All matches are found and automatically selected. DO NOT click inside the document otherwise you will lose the selections.
  7. Go to the Home tab and click the Aa icon in the Font group and change the case to lower case. This will change the case of everything selected.

[Link last checked March 2022]

h1

Word: Italicise numbers inside parentheses

December 2, 2021

In a comment on another blog post, one of my readers asked if there was an easy way to find all numbers and change them to italic. Well, there is (Option 1 below), but there was a further complication—some of these numbers were a range separated by a dash, and some were separated by commas. For example:

  • (123456)
  • (1-4)
  • (1, 5)
  • (1, 5, 12)

I couldn’t find an easy way to do this all at once, but you can do it by running several wildcard find and replace routines. If someone else has an easier or more elegant solution, please add it in the comments.

NOTES:

  • Tip: Just in case anything goes wrong, make a copy of your document before you start and do this in the copy until you are satisfied it works as you expect.
  • Tip: Only click Replace all once you are confident that it works.
  • Numbers are whole positive integers—no decimals, no ordinals, no negative numbers.
  • ‘Dash’ is the standard hyphen character on the keyboard, NOT an en or em dash, or a minus symbol.
  • All find and replace routines are done with Use wildcards turned on (Ctrl+h, click More, select Use wildcards).
  • Tip: Copy the find strings from here and paste into your Word find field.

Option 1: Find all numbers and change to italics

  1. Find: ([0-9])
  2. Replace: \1
  3. When in the Replace field, click Format > Font, and choose Italic.

Note: EVERY number in the document will be italicised.

Option 2: Find whole numbers only inside parentheses and change to italics

For example: (123456), (789), (23)

  1. Find: \(([0-9]@)\)
  2. Replace: ^&
  3. When in the Replace field, click Format > Font, and choose Italic.

Note: The numbers AND their surrounding parentheses will be italicised. See Option 6 for how to change the parentheses back to normal text.

Option 3: Find whole numbers separated with a single dash inside parentheses and change to italics

For example: (12-3456), (7-89), (2-3) [there are NO spaces before or after the dash]

  1. Find: \(([0-9]{1,9})(-)([0-9]{1,9})\)
  2. Replace: ^&
  3. When in the Replace field, click Format > Font, and choose Italic.

Note: The number ranges, the dashes, AND their surrounding parentheses will be italicised. See Option 6 for how to change the dash and the parentheses back to normal text.

Option 4: Find 2 numbers separated by a comma and a space, inside parentheses, and change to italics

For example: (1, 2), (25, 67)

  1. Find: \([0-9]{1,9}, [0-9]{1,9}\)
  2. Replace: ^&
  3. When in the Replace field, click Format > Font, and choose Italic.

Note: The numbers, the comma, the space, AND their surrounding parentheses will be italicised. See Option 6 for how to change the comma, space, and the parentheses back to normal text.

Option 5: Find 3 numbers separated by commas and spaces, inside parentheses, and change to italics

For example: (1, 2, 3), (25, 67, 345)

  1. Find: \(([0-9]{1,9}, [0-9]{1,9}, [0-9]{1,9})\)
  2. Replace: ^&
  3. When in the Replace field, click Format > Font, and choose Italic.

Note: The numbers, comma, spaces, AND their surrounding parentheses will be italicised. See Option 6 for how to change the commas, spaces, and the parentheses back to normal text.

Option 6: Change all commas, spaces, dashes, and parentheses back to normal text

  1. Find: ([, \(\)-]) (Note: there’s a space after the comma in this string)
  2. When in the Find field, click Format > Font, and choose Italic.
  3. Replace: ^&
  4. When in the Replace field, click Format > Font, and choose Not Italic.

 

h1

Word: Replace HTML em markers with italics

November 1, 2021

In a comment on another post, J had this problem: the text file that they’d copied into Word had the HTML code markers for emphasis (em enclosed by the greater than < and less than > arrows)and they wanted to get rid of these markers and change the text between those markers into italics. Unfortunately, WordPress won’t allow me write that code as it wants to automatically convert it into italics!

I solved their problem by using a wildcard find and replace in Word. Here’s how:

  1. Press Ctrl+h to open the Find and Replace window.
  2. Click More.
  3. Select the Use wildcards checkbox.
  4. In the Find field, type this (copy it if you think you’ll get it wrong; there are NO spaces in this string): (\<em\>)(*)(\</em\>) 
  5. In the Replace field, type this: \2
  6. While still in the Replace field, click Format (bottom left of the find/replace window), then Font, then select Italic. Font: Italic should display below the Replace field, as shown in the screenshot.
  7. Click Find Next. if you’re happy with what it found, click Replace. Only click Replace All if you’re confident that every instance of em has a closing em marker nearby.

How this works:

  • Each element of the Find is enclosed by parentheses. There are three elements — the opening em marker (#1), the text in between (#2), and the closing em marker (#3)
  • Because the greater than and less than symbols have special functions in Word’s wildcard find/replace, you have to ‘escape’ them by putting a \ in front of each
  • Because we don’t know which word or words or phrases or numbers are between the em markers, we use * to represent anything between an opening and a closing em marker
  • In the Replace, we don’t need the em markers anymore, so we omit them from the replace. But we do need the words that are enclosed by those em markers, and that’s the second element in the Find, so we type \2 to tell the second thing found to be replaced by itself.
h1

Word: Switch a footnote and following punctuation

June 3, 2021

Someone in an editors’ group on Facebook asked how to change the position of footnotes and punctuation. All their footnotes were followed by a period or a comma, and they wanted to shift the punctuation so that it came before the footnote, not after it.

Word’s find and replace using wildcards to the rescue! Here’s how:

  1. Press Ctrl+h to open the Find and Replace window.
  2. Click More, then select the Use wildcards checkbox.
  3. In the Find what field, type (^2)([.,])
  4. In the Replace with field, type: \2\1
  5. Click Find Next, then Replace for each one found. If you are confident, then click Replace All.

How this works:

  • ^2 is the code for footnotes that can only be used with wildcard searching (for normal searching, you’d use ^f, but you can’t use that in wildcard searches)
  • [.,] defines the range of things to look for after the footnote—in this case, a period or a comma
  • () the parentheses enclose each element of the Find, which means we can shift elements around in the Replace
  • \2\1 in the Replace tells Word to replace by putting the second element found (the punctuation) followed by the first element (the footnote), thus switching the positions

Note: If you just wanted to find only footnotes followed by a period (not a comma), you’d modify the Find to be (^2)(.) 

h1

Word: Hyperlinks are no longer blue

May 24, 2021

At some point, a Word document I received lost all the blue underlines representing hyperlinks for web addresses (URLs). The links were still there (you could hover over them and see the link pop up in the tooltip), but the text was ‘Normal’ not ‘Hyperlink’ style and pressing the spacebar at the end of the link wouldn’t turn it blue. There were far too many to fix individually.

I tried several things I found on the internet, but most solutions assumed the text of the URL had the Hyperlink style applied, even though it was no longer blue. However, mine had lost that, so only one solution that I found worked for me—the one from Suzanne S Barnhill, as explained here: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_word-mso_other-mso_2010/making-links-in-word-blue/bf5d471d-4a5f-4037-8e42-372de429864f.

Microsoft Support links are notorious for disappearing after a few years, so I’ve reproduced Barnhill’s solution, which worked for me, here, with thanks:

  1. Display field codes using Alt+F9. This will make your hyperlinks display as field code (e.g.  { HYPERLINK “https://example.com/&#8221; } )
  2. Press Ctrl+H to open the Replace dialog.
  3. Click More to expand the dialog.
  4. In the ‘Find what’ box, type ^d HYPERLINK
  5. With the insertion point in the (empty) ‘Replace with’ box, click Format, then Style.
  6. Select the Hyperlink style and click OK.
  7. Click Replace All.
  8. Press Alt+F9 again to toggle the field display back to results.

NOTES:

  • I found that while most hyperlinks changed back to blue underlining, some didn’t. Further inspection revealed that their field codes didn’t start with a space bwetween the { and HYPERLINK, so I repeated the steps above, this time typing ^dHYPERLINK (i.e. no space between the d and H) at Step 4. That found the remaining ones.
  • ^d represents any field code, and therefore ^d HYPERLINK looks for a HYPERLINK field code.

[Link last checked May 2021]

 

h1

Word: Reformat text inside quote marks using wildcards

April 16, 2021

A user on an editors’ Facebook group wanted to know if they could use a wildcard find and replace to reformat (perhaps by using different coloured text, highlighting, bold, italics etc.) the text in between quote marks to distinguish the quotations from other text in the document.

This is an ideal job for using wildcards in Word’s find and replace.

But some warnings apply:

  • There are several types of quote marks—single, double, with straight or curly variations for these, and some people may even type two single quote marks to represent a double quote mark, or use prime and double prime characters to represent a quote mark. The only SURE way to identify the marks used by the author are to copy them from the document and paste them into the Find field.
  • This Find/Replace DOES NOT WORK with single straight quotes—the character used for an apostrophe and to start and end a quotation is the same, so you won’t get the results you expect. Any string of text between one apostrophe and another will also be captured.
  • Make sure the quoted passage has both a starting and ending quote mark. If the end quote mark is missing, the change will occur to ALL text from the beginning quote mark to the next end quote mark found, which could be some pages away.
  • Beware of apostrophes used within a quotation when the quotation is surrounded by single curly quote marks—the Find will find up to the apostrophe, NOT to the ending single curly quote mark. This is because the symbol for an apostrophe and the ending single curly quote mark is the same character.
  • The safest practice is to check what’s found and click Replace if it matches, NOT Replace All.
  • ALWAYS ALWAYS ALWAYS test this on a copy of the document before you use it on the original document.

So, if you’re using double quotes (straight or curly), or single curly quotes, you can use this Find/Replace. I explain what the settings mean after these steps, if you’re interested. Meantime, here’s my solution, which works in all versions of Word:

  1. If you want to identify the quoted sections with a highlight colour, choose it first. Ignore this step if you want to change the font colour or styling.
  2. Select the text you want to change (e.g. entire document, selected paragraphs, selected columns or rows of a table).
  3. Press Ctrl+H to open the Find and Replace dialog box.
  4. Click the More button.
  5. Select the Use wildcards check box.
  6. Put your cursor into the Find what field—what you do next depends on the type of quote mark used in the document:
    • Straight double quotes: type the quote mark, followed immediately by an asterisk, then another quote mark.
    • Curly quotes (single or double): copy an opening quote mark from the document and paste it into the Find field, then type an asterisk immediately after it, then copy/paste the ending quote mark immediately after the asterisk.
  7. In the Replace with field, type: ^&
  8. Click the Format button.
  9. If you want to apply highlighting to the found text, select Highlight. If you want to apply character formatting (colour, bold, italics, etc.), select Font, select the character styling you want, then click OK.
  10. Your Find and Replace dialog box should look something like this, with the highlighting or character styling choice shown below the Replace with field:
  11. Click Find. Check the text found is what you expect—if so, click Replace, then click Find Next. Avoid clicking Replace All unless you are absolutely certain all quotes have a starting and ending quote mark and that there are no apostrophes within a quote.

What it all means

The quotes in the Find are self-explanatory. The asterisk between them says to find any number of characters (including spaces, punctuation marks, letters, numbers, etc.) between the first quote mark found and the next one found. NOTE: If the find/replace doesn’t match anything, check the type of quote marks you’re using and make sure you copy/paste the opening and closing ones into their correct position in the Find.

The ^& in the Replace says to replace whatever is found with itself (in other words, make no changes to the characters), and the font styling/highlighting below the Replace field tells word to make the replaced text that colour or style.

See also:

[Links last checked April 2021]

h1

Word: Find a special character written as text

February 15, 2021

When you want to find a special character, such as a paragraph mark, in Microsoft Word, you have to use a special character (in this case, ^p to search for all paragraph marks). And for most situations this works as you’d expect.

But if you’ve written ^p as text in a document, as I did for a document I’m writing on Word’s find and replace functions, where I need to type the characters used to find the special character, then you can’t search for that text string by typing ^p as the search term. Instead of finding what you wrote, you get results that list ALL paragraph marks in the document, and nothing matching what you wrote.

I tried all sorts of things with wildcards, escape characters etc. before asking a specialist editors’ group on Facebook, where one of the members pointed me in the right direction—you have to add another caret before the ^p, so ^^p.

Easy when you know how!

h1

Word: Add parentheses around a footnote number

November 20, 2020

Warning: I don’t use footnotes, and my authors rarely use them so footnotes and endnotes are not something I’m familiar with in Word.

M contacted me and asked how he could change the footnote numbers in his dissertation from unadorned superscripted numbers to those same numbers but with parentheses around them. He’d done some testing and had found a Quora post (https://www.quora.com/How-can-I-remove-all-the-brackets-around-the-numbering-of-the-footnotes-in-a-Word-Document) that detailed how to get rid of them, but couldn’t figure out how to add them automatically. Doing it manually in the body of the document and in the footnote area wasn’t going to work as there were hundreds of them.

The Quora post alerted me to something I wasn’t aware of—there’s a special wildcard symbol for footnotes: ^2. Armed with that information, I opened a new Word document, added some text and inserted some footnotes into it. Then I did a find and replace using wildcards and was able to automatically insert parentheses around all the superscripted footnotes, both in the body of the document and in the footnote area.

Wildcards must be on and you must have the cursor in the main body of the document, NOT the footnotes area, then:

  • Find: (^2)
  • Replace: (\1)

What this does is find a footnote number (the ^2 bit), but so that I could reference that in the replace, I surrounded it in parentheses, thus (^2).

The replace adds an opening and closing parenthesis either side of the found number (that’s the \1 bit).

NOTES:

  • You should only run this once, once you have all footnotes in place. If there are already parentheses around some footnote numbers, you will end up with two parentheses.
  • Any new footnotes you add will NOT have the parentheses. This does NOT change how Word auto numbers footnotes.
h1

Word: Find 3-digit numbers

October 8, 2020

A reader wanted to know how to find the 3-digit numbers in their document.

Using wildcards, that sounds easy enough, but the issue is that my initial attempt (find: ([0-9]{3}) ) found ALL strings of three numbers, not just the whole numbers that have ONLY three numbers. So, in a number like 12345, it found 123, then 234, then 345.

I needed to add more commands to force it to ignore longer numbers and numbers containing punctuation (e.g. decimal numbers and thousand separators). The only way to do that was to make it look for a space followed by a 3-digit number, followed by a space or any other ending punctuation (comma, period, colon, semicolon, question marks, exclamation point, closing parenthesis, closing square bracket should cover most variations).

Note: I use Word for Windows—the commands may be a little different in Word for Mac.

Instructions

  1. Press Ctrl+h to open the Find and Replace window.
  2. Click the Find tab.
  3. Click More to open the lower section of the window.
  4. Select the Use wildcards checkbox.
  5. In the Find what field, type: ( )([0-9]{3})([ .,;:\)\]\?\!])  (you may find it easier to copy this then paste it into the Find field; Note: the first set of parentheses contains a space, and the third set of parentheses has a space immediately after the opening square bracket).
  6. Click Find Next.

How this works

  • ( ) looks for a space 
  • ([0-9]) looks for any number from 0 to 9 immediately following the space, and {3} looks for any string of three numbers
  • ([ .,;:\)\]\?\!]) looks for a range (that’s the square brackets immediately inside the parentheses) containing any of these: a space, period, comma, semicolon, colon, then punctuation symbols that have to be ‘escaped’ because they are also special commands in wildcard searches—these are each preceded by a backward slash (the ‘escape’ character) and are a closing parenthesis, a closing square bracket, a question mark, and an exclamation point.
h1

Word: Transpose punctuation characters at the end of a quotation mark

September 26, 2020

In the main, British English and American English treat punctuation at the end of speech quotation marks differently—US English has the punctuation inside the final quotation mark, whereas British English has it outside (there may be some exceptions to this general rule, but let’s just go with what usually happens).

If you need to style speech from British English to US English, you need to find all the various punctuation marks that come after a quotation mark and transpose them so they come before the quotation mark. You can do with with a find and replace using wildcards.

These instructions are for Word for Windows, but you should be able to do something similar in Word for Mac.

  1. Before you start, copy an ending quotation mark to the clipboard. Why? Because there are various symbols used for quotation marks (straight, curly, even a single or double prime) and you want to make sure you get the one you use.
  2. Press Ctrl+h to open the Find and Replace window.
  3. Click More.
  4. Check the Use wildcards checkbox.
  5. In the Find what field, type: (”)([.,;:\?\!]) (Note: In the first set of parentheses PASTE the quotation mark you copied at Step 1.)
  6. In the Replace with field, type: \2\1\
  7. Click Find Next, then Replace on each that you want to transpose. Only click Replace All once you are confident that you won’t inadvertently change something you shouldn’t.

How this works:

  • In the Find, you have two elements, each surrounded by a set of parentheses—these are elements 1 and 2.
  • In the first element, you paste the quotation mark and make sure it is surrounded by opening and closing parentheses.
  • In the second element, you also have opening and closing parentheses, then within those you have a set of opening and closing square brackets—these indicate that you are looking for a range of characters, and the characters you’re looking for in this instance are a period, a comma, a semicolon, a full colon, a question mark, and an exclamation point. The question mark and exclamation point are special characters in a wildcard Find so you must indicate you want the actual character and not the special function it has. You do this by ‘escaping’ each of these characters with a backslash.
  • In the Replace, you want to position element 2 immediately before element 1 (i.e. transpose it), with no spaces or anything else, which is represented by \2\1\.