Posts Tagged ‘wildcards’

h1

Word: Find multiple manually entered numbers and delete

April 22, 2019

I copied a very long manually numbered list (more than 300 numbered list items) from the internet into Notepad (to strip out the formatting), then into a Word document. Unfortunately, the numbers remained, and applying Word’s numbering didn’t get rid of them. What to do? Use Word’s Find and Replace with wildcards, of course!

My aim was to delete all the numbers and the space, en dash, space following each number, to end up with a list I could apply Word’s auto numbering to.

Here’s how I did it (NOTE: If you’re doing something similar, work on a COPY of your document first to make sure this works as you want it to):

  1. Open the Find and Replace dialog box (Ctrl+h).
  2. Click More.
  3. Select the Use Wildcards checkbox.
  4. In the Find what field, type: (<[0-9]@>)( – )
  5. Leave the Replace with field empty.
  6. Click Replace All.

Voilà! Almost all the numbers were gone, except for a few that used hyphens instead of en dashes or that didn’t have a space before or after the en dash, but I spotted these easily and fixed them manually.

How this works:

  • The first element (in the first set of parentheses) comprises several parts:
    • < and > indicate the beginning and end of a ‘word’, respectively
    • [0-9] indicates any number in the range from 0 to 9, and with the < in front of it, any ‘word’ that starts with a numeral
    • @ says to look for whatever immediately preceded this symbol as many times as required (i.e. a number from 0 to 9) until you reach the end of word marker (in other words, a whole number of any length)
  • The second element (second set of parentheses) looks for a space, en dash, space immediately following the number found in the first element
  • By leaving Replace with empty, you’re replacing whatever was found that matched the Find with nothing—in other words, you’re deleting whatever was found.

 

h1

Word: Find and replace multiple asterisks used as separator lines

February 15, 2019

On one of my editing forums, someone had a situation where the author had used many long strings of asterisks to separate various parts of the document. The length of these asterisk ‘lines’ weren’t the same—sometimes the author had used 3 asterisks, other times they’d used 4 or 8 or 35 or some other random number of asterisks. How to get rid of them all at once? Enter Word’s wildcard find and replace feature!

  1. Press Ctrl+H to open the Find and Replace dialog box.
  2. Click the More button to show more find/replace options.
  3. Select the Use wildcards checkbox.
  4. In the Find what field, type: (^013)(\*{2,50})(^013)
  5. In the Replace with field, type: \1\3
  6. Click Find Next to find the first instance, then Replace to replace the multiple asterisks with a paragraph mark.
  7. Repeat step 6 as many times as you need to be confident that it’s finding the right things. Once you’re confident, click Replace All to run through the whole document and fix all instances.

Explanation for how this works:

  • (^013) looks for a paragraph mark (this indicates the end of the previous line of text). This string defines the first section of the Find.
  • (\*{2,50}) looks for two or more asterisks, up to 50 asterisks (yes, you can change the numbers inside the curly braces to suit your situation— if you think you might have some lines with 100 asterisks, then change the 50 to 100; if you don’t know what the upper limit is, then leave it empty [i.e. use \*{2,}). This string defines the second section of the Find. NOTE: An Asterisk is a special character in wildcard searches, so you need to ‘escape’ it by putting a backward slash in front of it.
  • (^013) looks for a paragraph mark immediately following a string of asterisks. This string defines the third and last section of the Find.
  • \1 replaces the first part of the wildcard string with itself. In other words, the paragraph mark found is replaced with itself, so no change apparently occurs.
  • \3 replaces the third part of the wildcard string with itself. In other words, the paragraph mark found is replaced with itself, so no change apparently occurs.

A note about ^013: In an ordinary find/replace, you would use ^p for a paragraph mark, but this doesn’t work in a wildcard find/replace—instead, you have to use ^013.

h1

Word: Find ‘ing’ words and change their formatting

September 21, 2018

Tessa had a problem—she needed to find all words ending in ‘ing’ in her document and format the whole word in some way.

NOTE: This find/replace will find ALL words ending in ‘ing’, but not words ending in ‘ings’ or ‘ingly’. And words such as ‘going’, ‘bring’, ‘sing’, ‘king’, and ‘thing’ also get found. But if your aim is to find ALL words ending in ‘ing’ that’s what you’ll get.

Simplest solution: If you didn’t want the whole word to be formatted, just the ‘ing’ bit, then it’s easiest to use the standard find/replace, with the ‘Match Suffix’ option turned on. See Method 1 below.

However, if you want the whole words found and formatted, you’ll need to use wildcards. See Method 2 below.

Method 1

  1. Open the Find and Replace window (Ctrl+h).
  2. Click More to see the extra search options.
  3. In the ‘Find what’ field, type ing
  4. Select the Match suffix checkbox.
  5. Put your cursor in the ‘Replace with’ field, then click Format at the bottom of the window.
  6. Click Font.
  7. Select the formatting you want to apply to the found ‘ing’s—you can choose one or more options from this window. Then click OK to close the Font window. The formatting you selected is listed below the empty ‘Replace with’ field.
  8. Click Find Next, then click Replace as many times as you need to be comfortable that the find/replace works as you want it to. If you’re happy with the matches, then click Replace All.

Method 2

This method uses Word’s find and replace with wildcards.

  1. Open the Find and Replace window (Ctrl+h).
  2. Click More to see the extra search options.
  3. Select the Use wildcards checkbox.
  4. In the ‘Find what’ field, type <[A-Za-z]@ing>
  5. Put your cursor in the ‘Replace with’ field, then click Format at the bottom of the window.
  6. Click Font.
  7. Select the formatting you want to apply to the found ‘ing’ words—you can choose one or more options from this window. Then click OK to close the Font window. The formatting you selected is listed below the empty ‘Replace with’ field.
  8. Click Find Next, then click Replace as many times as you need to be comfortable that the find/replace works as you want it to. If you’re happy with the matches, then click Replace All.

How this wildcard find/replace works:

  • < and > represent the start (<) and end (>) of a word (this specifies that you’re looking for a whole word)
  • [A-Za-z] look for any upper any lower case letters
  • @ing tells Word to repeat looking for upper/lower case letters until it finds ing

What about ‘ing’ in the middle of a word?

Follow Steps 1 to 3 in Method 2 above, then in the ‘Find what’ field, type <[A-z]@ing[a-z]@>. Continue with Steps 5 to 8 above.

NOTE: You can’t format just a part of the replace (i.e. you can’t make just the ‘ing’ in ‘fringed’ red or bold)—it’s all or nothing.

h1

Word: Make some specific text bold

September 14, 2018

As most people would know, you can apply bold formatting in Word using Ctrl+b or the Bold icon on the Home table on the Ribbon.

But what if you want more? What if you have some specific text scattered throughout your document that you want to make bold in one action? This was the issue Colin faced. In a comment on one of my other blog posts, Colin asked if there was a way to apply bold a set of characters that all started with the same code, but had different numbers after that code (e.g. like product codes). In his example, he had a lot of instances of VA-001, VA-002, etc. with the last three digits being different each time. He’d tried the method I’d documented in my earlier post, but he could only bold part of the code, not all of it.

As with any find and replace, once you identify the pattern, it’s easy enough to test various ways of finding a match and then applying the change to it. I figured out two methods—both using wildcards. The first method assumes there are only ever three characters (not, 1, 2, 4, etc.) after the VA- part, while the second applies to any length of the ‘word’ after VA-.

For both methods, open the Find and Replace window (Ctrl+h), click More, then check the option for Use wildcards.

Method 1: Only three characters

  1. In the Find field, type: (VA-)(???)
  2. In the Replace with field, type: \1\2
  3. With your cursor still in the Replace with field, click Format, then Font, then select Bold. You should see Font: Bold directly below the Replace with field (see screenshot).
  4. Click Replace a few times to make sure the find/replace is doing what you expect it to. Once you are satisfied, you can click Replace All.

Notes:

  • In the Find, the code is separated into two parts, both surrounded by parentheses—the VA- part, which is a constant in what Colin had, and three question marks (???). A single question mark represents any single character, so by typing three question marks, you’re asking Word to look for ANY three characters (letters and/or numbers) after the VA- part. If you only had two characters, then you’d type two question marks; if you had 4, then you’d type four, etc.
  • In the Replace, you’re replacing what was found in both parts with itself. In other words, you’re not changing anything. What you are doing in the Replace, though, is specifying that what you find and replace with itself is now bold (step 3).

Method 2: Any number of characters

  1. In the Find field, type: (VA-)(*>)
  2. In the Replace with field, type: \1\2
  3. With your cursor still in the Replace with field, click Format, then Font, then select Bold. You should see Font: Bold directly below the Replace with field (see screenshot).
  4. Click Replace a few times to make sure the find/replace is doing what you expect it to. Once you are satisfied, you can click Replace All.

Notes:

  • In the Find, the code is separated into two parts, both surrounded by parentheses—the VA- part, which is a constant in what Colin had, and an asterisk followed by a right chevron arrow. The asterisk represents any number of characters from one to infinity. Because a ‘character’ in Word could be a space, you don’t want it to find EVERY character after the VA- part—you’d get the whole document! So you add the > to tell Word to stop at the end of the ‘word’ it finds. In other words, it will stop at any character that typically follows a set of adjacent characters (a ‘word’), such as a space, period, comma, colon, semicolon, etc.
  • In the Replace, you’re replacing what was found in both parts with itself. In other words, you’re not changing anything. What you are doing in the Replace, though, is specifying that what you find and replace with itself is now bold (step 3).

[Links lat checked September 2018]

h1

Word: Add a character to all items in a long list, and style it in a colour

July 27, 2018

Here was a tricky one posed by my husband first thing this morning. He had a very long column in a table (some 2750+) rows, in which he had some sort of code, like a product identifier. Fortunately, the codes were all the same — they were all K-xxxx, where ‘xxxx’ was a 4-digit number (e.g. K-1234, K-5432, etc.).

He wanted to add a zero immediately after the hyphen. Easy enough. But he wanted this zero character to be blue! Hmmm… (and no, I have no idea why! Update: He had a list of catalogue numbers, but when the company used up all the 4-digit numbers, they changed to 5-digit numbers. To sort them correctly by catalogue number in Word, he needed to add a leading 0 to the 4-digit ones, but he wanted to show that the 0 wasn’t part of the original number, thus the colour.)

After a few minutes of testing I achieved what he wanted. I had to do three find and replace passes, with one of them a wildcard find/replace — the first pass added the 0, the second changed the colour of the hyphen and its trailling zero to blue, and the third changed the colour of the hyphen back to black, leaving just the 0 after the hyphen in blue text.

NOTE: If you’re doing something like this on your own document, either work on a COPY until you’ve refined the procedure and know you won’t inadvertently replace something you shouldn’t have, OR at the ‘Replace All’ steps below, click ‘Replace’ instead, followed by ‘Find Next’. You will have many more clicks to do, but it’s a safer option.

Here’s what I did:

First pass – add a zero after the hyphen:

  1. Open the Find/Replace window (Ctrl+H).
  2. In the Find What field, type K-
  3. In the Replace With field, type K-0
  4. Select the list (or column in a table) you want to apply this change to
  5. Click Replace All. This adds a zero after the K-, so you end up with codes like K-01234, K-05432, etc.
  6. Leave the Find and Replace window open.

Second pass – make the hyphen and the zero another colour:

  1. For the second pass, click outside the selection to position the cursor away from it (I had to do this because as soon as I entered the wildcard string for the colour, ALL the selected text changed to blue, without me even clicking Replace All — very strange).
  2. In the Find/Replace window, click More.
  3. Select the Use wildcards checkbox.
  4. In the Find What field, type (-)(0) (there are NO spaces in this string).
  5. In the Replace With field, type \1\2 (there are NO spaces in this string).
  6. With your cursor still in the Replace With field, click Format.
  7. Select Font.
  8. Choose a colour from the Font color drop down.
  9. Click OK.
  10. Check the Replace With field — it should have Font color: <name of colour> below the field. The only thing below the Find What field should be Use wildcards. If you have something different, repeat these steps, and make sure you follow Step 6 exactly.
  11. Select the list (or column) again.
  12. Click Replace All. This changes the hyphen and trailling zero to the colour you selected.
  13. Leave the Find and Replace window open.

Third pass – remove the colour from the hyphen:

  1. For the third and final find and replace pass, click outside the selection to position the cursor away from it. Don’t forget to do this!
  2. Clear the Use wildcards checkbox.
  3. In the Find What field, delete the existing characters, then type a hyphen.
  4. In the Replace With field, delete the existing characters, then type a hyphen.
  5. With your cursor still in the Replace With field, click Format, select Font, then in the Font Color drop-down box, select Automatic (or another font colour).
  6. Select the list (or column) again.
  7. Click Replace All. This changes the hyphen colour to the colour you selected in Step 5.

 

h1

Word: Wildcard find and replace for numbers inside parentheses

July 22, 2018

In a comment on another post (https://cybertext.wordpress.com/2015/07/14/word-wildcard-find-and-replace-for-numbers-and-trailing-punctuation/), AVi asked if there was a way to find percentage numbers (e.g. 56%) that were inside parentheses, and replace them with the same number but without the parentheses — i.e. (56%) becomes 56%.

There is, but it’s a bit trickier than usual because parentheses are also special characters in Word’s find/replace lexicon—these have to be ‘escaped’ for Word to treat them as normal characters and not as special characters.

In figuring this out, I also took into account that there might be single numerals (e.g 4%), triple numerals (e.g. 125%), and numerals with one or more decimals (e.g. 75.997%).

Here’s what I came up with that worked for all those scenarios:

  1. Press Ctrl+H to open the Find and Replace dialog.
  2. Click More, then select the Use wildcards check box.
  3. In Find What, type: ([\(])([0-9]*%)([\)])
  4. In Replace With, type: \2
  5. Click Find Next, then click Replace once the first is found. Once you’re happy that it works, repeat until you’ve replaced them all.

What the find and replace ‘codes’ mean:

The three elements (each is enclosed in parentheses) of the Find are:

  1. ([\(]) — You need to find a specific character (the opening parenthesis), so you need to enclose it in parentheses. However, because parentheses are special wildcard characters in their own right, you need to tell Word to treat them as normal text characters and not as special characters, so you put in a backslash ‘\‘ (also known as an ‘escape’ character) before the (, AND surround this string in square brackets [ ] (otherwise, it won’t work).
  2. ([0-9]*%) — The [0-9] represents any number from 0 to 9; the * represents any more characters immediately after that number (more numbers, or a decimal point), thus not limiting the find to only single digit numbers; and the % symbol says this string of numbers found must finish with that symbol. This finds numbers like 2%, 25%, 283%, 25.4%, etc.
  3. ([\)]) — You need to find the closing parenthesis, so you need to enclose it in parentheses. However, because the closing parenthesis is a special wildcard character in its own right, you need to tell Word to treat it as a normal text character and not as a special character, so you ‘escape’ it with a backslash ‘\‘ before the ), then surround that string in square brackets.

There are no spaces preceding or trailing any of these elements, or in between them, so if you copy the code from this blog post, get rid of any preceding spaces otherwise it won’t work .

For the Replace: \2 — Tells Word to replace the second element of the Find with what was in the Find (i.e. a number followed by a % symbol) .

AVi: I hope this solves your problem. Donations to keeping this blog ad-free gratefully accepted (see the link at the top right of the page).

 

h1

Word: Finding duplicate words

July 11, 2018

I had a long list (57 pages!) of Latin species names, sorted into alphabetical order. I’d separated the words so that there was only one word on each line. My next task was to go through and remove all the duplicates (i.e. a word immediately followed by the same word) so I could add the final list to my custom dictionary for species in Microsoft Word. I started doing it manually—it’s easy enough to find duplicates when the words are familiar, but for Latin words, my brain just wasn’t coping well and I was missing subtle differences like a single or double ‘i’ at the end of a word. There had to be a better way…

And there is! Good old Dr Google came to the rescue, and with a bit of fiddling to suit my circumstances (one word on each line), I got a wildcard find and replace routine to find the duplicates.

NOTE: DO NOT do a ‘replace all’ with this, in case Word makes unwanted changes. In my case it didn’t treat the second word as a whole word for matching purposes (e.g. it thought banksi, banksia, and banksii were duplicates). Even though I had to skip some of these, it was still worth it to automate much of the process. Another caveat—if you have several lines of the same word, each pair will be found, but you’ll have to run the find several times to get them all. Much better to move your cursor into Word and delete the excess multiple duplicates when you find them. You may still have to do a couple of passes over the document, but the heavy lifting will have been done for you.

Here’s what I did to get it work:

  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 (<*>)^013\1 (there are no spaces in this string).
  4. In the Replace With field, type \1 (there are no spaces in this string either).
  5. Click Find Next.
  6. When a pair of matching whole words is found, click Replace. NOTE: If the second word is only a partial match for the first word, click Find Next.
  7. Repeat steps 5 and 6 until you’re satisfied you’ve found them all.

How this works:

  • (<*>) is the first element (later represented by \1) of the find. The angle brackets specify the start and end of a word, and the ‘word’ is anything (represented by the *). In other words, you’re looking for a whole ‘word’ of any length and made up of any characters (including numbers).
  • ^013 is the paragraph marker at the end of the line. In my situation, each word was on its own line with a paragraph mark at the end of the line. If you don’t have this situation, leave this out and replace it with a space (two repeated words in the same line are separated by a space). NOTE: Normally you can find a paragraph mark in a Find with ^p, but not with a wildcard Find—you have to use ^013.
  • \1 is the first element. In the Find, it means the duplicate of whatever was found by (<*>); in the Replace, it means replace the duplicated word with the first word found.