Wildcards and Carriage Returns in Word

I’m not quite sure why but I often find myself doing various editing in Word. Not just just normal editing but more like parsing text trying to get it ready for import into a database or a spreadsheet. This often involves editing at a level that, I suspect, many users are not familiar with. Operations such as removing carriage return, converting tab characters to single spaces are all operations that you often have to do.

One of the things I often do (for reasons which escape me now, but it is always sensible at the time) is to replace carriage returns with some sequence of characters that does not appear anywhere else in the document. My sequence of choice is usually xxxyyyzzz. Having such a sequence means that I can restore the carriage returns at a later time, once I have done some other edit operations.

What is nice about Word is that it allows you to do these type of edits very easily. All you need to do is bring up the search/replace dialogue box (either by the menu or by Ctrl/H). To replace carriage returns, you simply use ^p in the Find box. In the Replace box you can type whatever you like (it will often be xxxyyyzzz, if you are me).

When you need to reverse the operation you just put ^p in the Replace box.

All good so far, but if you start using wildcards to carry out more sophisticated searches then things start to go a little wrong. For those of you that do not know, wildcard searching is when you need to search for, say h???o. where you want to find a string of text that starts with ‘h’ and ends with ‘o’ but you do not care what is in between. Word enables you to do this type of search with a search string that looks like h*o. This says to search for any string of characters that starts with an h, ends with an o an has any character, and any number of characters, in between.

To do this type of search you have to tick the box marked wildcard searching. If you now try to use ^p as a search phrase, you will get a message that says that ^p cannot be used with wildcard searching. This is not good, as you (well me) often need to search for carriage returns.

And this has been my understanding for years, you cannot search for carriage returns at the same time as carry out wildcard searches. Every time I needed to search for a carriage return, but also need to use wildcard searching I had to find another way of doing whatever it was I was trying to do, which was sometimes long winded in the extreme.

Recently, I had a pressing need to do both these things and there was not an obvious work around. I had googled for a solution a number of times in the past, without success, but I thought I’d give it another go,more out of hope than expecting to find anything.

Actually, I found exactly what I was looking for at Jack Lyon’s blog.

Essentially, you just use the ASCII code. So instead of putting ^p as a search string, you use ^013. And this works in wildcard searching.

I know Jack has blogged this solution already, but I just wanted to note it myself so that I can easily find it when I need it in a few months time, as I inevitably will!

Thanks Jack, nice tip.


2 thoughts on “Wildcards and Carriage Returns in Word”

  1. Thanks! Good post content and writing style.
    ^13 has a drawback. When you do paragraph mark replacement, you end up with something which looks like it should work, but then the formatting fails when applied.
    Not a big deal if you are parsing text (I use Word for this too – very excellent!) But if you actually want to word process, and get pretty paragraph layouts and nice headings a-la Word themes and styles, you’re into a minefield.
    I’m going to try the xxxyyyzzz thing and see if I can’t then switch back to non-wildcard ^p replacement. Maybe that will preserve the Word-y functional behaviour.
    But again, Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *