Talking tech: Find and Replace

In this latest Talking tech post, Andy Coulson looks at how Find and Replace can speed up editing and styling references.

In keeping with this month’s theme of references for The Edit, I’m going to take a look at how we can use one of Word’s most powerful in-built tools – wildcard Find and Replace. References have to conform to tight formatting rules, and these lend themselves to using wildcard Find and Replace to tidy them up. This is particularly handy if you have a paper that was written with one form of referencing that needs to be changed to a different one. I’ll give a brief introduction to wildcards, then share some examples that focus on the type of issues in references and finally I’ll take a quick look at using these with Paul Beverley’s FRedit macro and PerfectIt.

Before we get cracking, a word of warning. Many academic authors use reference management software like Mendeley to produce reference lists. This software manages the references outside of Word and links to the Word document. With Mendeley you see references as form fields in the document. If you make changes, the next time the document is opened with a connection to Mendeley the reference list and links are overwritten, losing your edits. If you think this is the case, make sure you clarify how your client wants references edited.

Find and Replace can also be a blunt instrument, so use it with care. While you are refining your search, work on a copy of your text. And don’t use ‘Replace All’ unless you are very clear what you are replacing. It is safer to step through the things being found by using the ‘Replace’ or ‘Find Next’ (if you want to leave something unchanged) buttons.

Wildcards

Word’s Find and Replace feature has a number of hidden extras. If you’ve not already found these, they can be revealed by clicking the ‘More’ button under the ‘Replace with:’ field.

This opens the menu shown below and, as we are going to look at wildcards, we need to check the ‘Use wildcards’ option.

So, what is a wildcard? It is simply a character that can be used to represent anything else. A very simple example is using the character ‘?’ in a wildcard search. If you have ‘Use wildcards’ selected, put ‘r?n’ in the ‘Find what:’ field and ‘ran’ in the ‘Replace with:’ field then press ‘Replace All’, you would replace all instances of ‘ron’, ‘run’, ‘ren’, etc with ‘ran’. The ‘?’ tells Word to find any letter, so it looks for the pattern ‘r’ followed by any letter, followed by ‘n’. This does require a little thought, because what you have now also done, potentially, is turn ‘iron’ into ‘iran’, and a ‘wren’ would become a ‘wran’.

Now that example should alert you to the problems with this, but this is a very simplistic example and to do something more useful we need to dive deeper. Wildcards allow you to specify more complex patterns in the text, and as we will see in the examples below we can do some quite complex searches, often with a little trickery.

As this is a (relatively) short article I’m not going to be able to go into all of the possibilities. The best way to learn how to use these is to experiment. If you want some help, there are a number of resources available:

Examples

Let’s have a look at a couple of reference-related examples in detail so we can see how these work. For the referencing gurus out there, I am going to omit some required information from the references for clarity and play a bit fast and loose with referencing styles.

Example 1: Initials in names

Different referencing systems use different conventions for citing authors’ names in the reference list. So, you may have Hartley, J.R. (APA style), Hartley JR (Vancouver style) or even J.R. Hartley. Usually a reference list will be (largely) consistent, so it has a pattern we can find and a pattern we can replace it with. We will start with these three references:

A.N. Author. (1986). Writing for beginners (2nd ed.). Jones Books

S. Editor. (2021). Editing for fun and profit (1st ed.). MyPub Ltd

I.S.B. Nash. (2007). Cataloguing books (3rd ed.). Big Books Inc.

With Find and Replace we need to break problems down into manageable chunks, and sometimes multiple searches, that can be implemented by Find and Replace. Let’s assume we need to change author-name style in the list to Vancouver. The first issue we can tackle is the structure of the author names – setting them after the surname.

To do this we use the ‘Find what:’ string¹

^013([A-Z.]@) ([A-z]@).

What this does is:

  1. Looks for a line break: ^013 (‘^’ tells Word the number following is a character code. Note that these are for Windows and may be different on a Mac. You can find a list of these in the Wildcard Cookbook and macro book mentioned above).
  2. Looks for one or more initials: ([A-Z.]@) – the round brackets are grouping together and are important when we come to replace things; the [A-Z.] looks for capital letters or a full stop and the @ tells Word to look for one or more occurrences of these. Note that there is a space after this term, like in the text.
  3. Now looks for a capitalised word: ([A-z]@) – a combination of upper- and lower-case letters.

Now we replace the surname first and the initials after using this ‘Replace with:’ string:

^p\2 \1

This replaces the text as follows:

  1. We put the line break back in: ^p – note that we are using a different code here. ‘Why?’ you may ask. Because Word …
  2. Next we put the surname in: \2 – the \2 tells Word to use the second item in round brackets, what we found with item 3 above.
  3. Finally, we add the initials back in after a space – \1 – using the first bracketed item we found in item 2 above.

This leaves us with:

Author A.N. (1986). Writing for beginners (2nd ed.). Jones Books

Editor S. (2021). Editing for fun and profit (1st ed.). MyPub Ltd

Nash I.S.B. (2007). Cataloguing books (3rd ed.). Big Books Inc.

Now we need to remove the extra full points. We have to do that in two steps, by taking out all the relevant full points and then adding back the one after the final name.

So, removing the full points we use this ‘Find what:’ string, which simply finds one capital letter followed by one full point.

([A-Z]).

We then put the capital letter back in using this ‘Replace with:’ string:

\1

This gives us:

Author AN (1986). Writing for beginners (2nd ed.). Jones Books

Editor S (2021). Editing for fun and profit (1st ed.). MyPub Ltd

Nash ISB (2007). Cataloguing books (3rd ed.). Big Books Inc.

Now we add the final full point back in before the bracket with the year. That bracket gives us a pattern we can identify to put the full point in the right place. So, we use the ‘Find what:’ string:

([A-Z]) \(

As before, the round brackets contain a string to find one capital letter; this is followed by a space and finally by \(. ‘What is that?’ you may ask. Well, we use brackets to create a sequence in the search string that we can return to later, so in wildcard searches round brackets (and a number of other symbols) work as commands. In order to refer to those symbols we need to escape it, which means adding a backslash in front, so \( finds an opening round bracket. We can then use the following ‘Replace with:’ string to add the full point.

\1. ^40

As before \1. adds the initial back with the full point and ^40 puts an open bracket back. Again, note the different way that replace refers to the character, but that’s just the way it works I’m afraid. This then gives us:

Author AN. (1986). Writing for beginners (2nd ed.). Jones Books

Editor S. (2021). Editing for fun and profit (1st ed.). MyPub Ltd

Nash ISB. (2007). Cataloguing books (3rd ed.). Big Books Inc.

Example 2: Adding styling

I realise this is not proper Vancouver referencing, but I want to show you how we can add styling using wildcards. In this example we will apply italics to the book titles. As before, we need a pattern to recognise which part is the book title. In this case we have the end of the year ‘). ’ and the start of the edition ‘ (’. However, in order to find the title we have to find more text, the two brackets before and after, which we don’t want in italics. This means we need to be a bit cunning!

To do this we use this ‘Find what:’ string:

(\). )([A-z .]@)(\([0-9])

  1. (\). ) finds a closing bracket \), followed by a period and a space and we want to keep those, so we group them.
  2. ([A-z .]@) looks for a mix of upper- and lower-case letters, spaces and full stops – our surname and initials.
  3. (\([0-9]) looks for an open bracket \( plus a number – the characters at the start of the edition.

If we then replace this with:

\1%%\2%%\3

we put %% before and after the characters of the title that we want to italicise:

Author AN. (1986). %%Writing for beginners %%(2nd ed.). Jones Books

Editor S. (2021). %%Editing for fun and profit %%(1st ed.). MyPub Ltd

Nash ISB. (2007). %%Cataloguing books %%(3rd ed.). Big Books Inc.

We now have the title clearly marked, so can then style that. We search for the modified title with %% before and after.

%%([A-z .]@)%%

We then replace that with just the title text, which we have put in round brackets, so \1 goes in the ‘Replace what:’ field. Before we replace this, we need to tell Word to italicise this text. If you tap on the ‘More’ button in the bottom left you will see a ‘Format’ button. Pressing on this pops up the menu shown below. If you select ‘Font’ the font dialogue box pops up and you can select ‘Italic’. You will also see ‘Font: Italic’ appears under the ‘Replace with:’ field.

Running that Find and Replace gives us our final list:

Author AN. (1986). Writing for beginners (2nd ed.). Jones Books

Editor S. (2021). Editing for fun and profit (1st ed.). MyPub Ltd

Nash ISB. (2007). Cataloguing books (3rd ed.). Big Books Inc.

Integrating with Macros and PerfectIt

Wildcard Find and Replace searches like this are real timesavers, but there’s no obvious way of saving these and using them again and again. There is a short history for both the ‘Find what:’ and ‘Replace with:’ fields if you click the down arrow at the right of each, but I don’t find this particularly helpful.

Both Paul Beverley’s FRedit macro and PerfectIt support using wildcards, so offer a way to reuse multiple Find and Replace searches. As the point of using things like macros and wildcards is to save you time sometimes the investment of time to set up those searches in a macro or PerfectIt may not add up compared to just running the searches. For example, I do some work on papers for academic journals that are about 6,000 words long. I get material for multiple different journals, so it is quicker for me to just use a few Find and Replace searches rather than setting up, say, FRedit. However, a book or multiple papers for the same journal would change that, and setting up FRedit or PerfectIt would then be worthwhile. Having said that, writing this has convinced me to create a file of Find and Replace searches I can refer back to. I will probably format this as a FRedit list so I can use these with that macro.

PerfectIt allows you to perform wildcard searches in the ‘Wildcard’ tab. This lets you use all the features of wildcards in Word Find and Replace and adds a couple of neat features. The first of these is that you can add an instruction or prompt that explains what the search is doing, because, as we saw above, patterns can crop up in unexpected places. The second of these is that you can add exceptions. PerfectIt’s manual page uses the example of apostrophes being added to numbers followed by ‘s’, so ‘we have 3s, 4s and 5s chosen’ is correct. However, if we talk about ‘Page 4’s content’ we need the apostrophe. We can make numbers after the word ‘Page’ an exception.

FRedit is a scripted version of Find and Replace, so runs multiple Find and Replace searches from a list. It uses all the forms in Word Find and Replace, but has a few little tweaks you need to use in the file of searches we set up. FRedit doesn’t present us with the dialogue boxes that Word Find and Replace does. So in the file we use ‘|’ to separate the ‘Find what:’ and ‘Replace with:’ terms on a line and add ‘~’ at the start of the line if we are using wildcards. We can also add formatting easily. I sometimes use FRedit to quickly highlight things so I can then take my time on a read-through to check the context. For example, if you have an app called Balance it needs capitalising, but if you also talk about keeping your balance it doesn’t, so you have a mix, but the context will determine which you use.

Hopefully this has given you some ideas and encouraged you to go and experiment. I can honestly say learning how to use wildcards and Find and Replace efficiently has helped speed up my editing enormously. Combining these with FRedit or PerfectIt speeds things up even more where you have longer pieces or house styles you use regularly.


1 Paul Beverley has flagged that while ‘[A-z]@’ will find any letter it does not pick up on accented letters. A better solution is ‘[A-Za-z]@’.

About Andy Coulson

Andy Coulson is a reformed engineer and primary teacher, and a Professional Member of CIEP. He is a copyeditor and proofreader specialising In STEM subjects and odd formats like LaTeX.

 

 

About the CIEP

The Chartered Institute of Editing and Proofreading (CIEP) is a non-profit body promoting excellence in English language editing. We set and demonstrate editorial standards, and we are a community, training hub and support network for editorial professionals – the people who work to make text accurate, clear and fit for purpose.

Find out more about:

 

Photo credits: magnifying glass by towfiqu barbhuiya on Canva, joker by Roy_Inove on Pixabay.

Posted by Harriet Power, CIEP information commissioning editor.

The views expressed here do not necessarily reflect those of the CIEP.

Leave a Reply

Your email address will not be published.