Word: Delete tabs and page numbers from the end of a paragraphFebruary 13, 2012
One of my colleagues wanted me to grab all the tables of contents (TOCs) out of 18 separate chapters of a really long report and put them in a single document that she could share with the stakeholders. She only wanted the outline numbering and the heading titles, down to three TOC levels.
I copied each table of contents and pasted it as plain text into a new document. That preserved the outline numbering, followed by a tab, then the heading title, but it also added a tab after the heading title and the page number, neither of which were required. As the plain text version of the 18 chapter TOCs came to well over 12 pages (!), there were several hundred lines, one for each TOC entry. I could manually delete these tabs and page numbers, but that was going to get very tedious very quickly.
What I wanted was a single command to get rid of the end tabs followed by the page number. But I needed to keep the tabs after the outline numbers.
Find and replace wildcards to the rescue!
My first attempt only found the single digit page numbers and replaced them, so I tested a bit more to find a way to delete page numbers no matter what their length.
- Open Word’s Find and Replace dialog box (Ctrl+H).
- Click More to show more options.
- Select the Use wildcards check box.
- In the Find what field, type: (^t)([0-9]*)(^13)
Note: There are NO spaces in this string, the t must be lower case, and there’s an asterisk (*) immediately after [0-9] bit.
- In the Replace with field, type: ^p
Note: The p must be in lower case.
- Click Find Next, then click Replace to test that it works fine. If so, click Replace All.
Explanation for how this works:
- (^t) looks for a tab character; you MUST use a lower case t and precede it with the ^ (Shift+6). Because you are using wildcards, you need to surround the characters you want to find in parentheses.
- ([0-9]*) looks for any numeral of any length that follows immediately after the tab character. The square brackets indicate a range — in this case any numeral from 0 to 9 will be found. And the asterisk looks for any number of characters that are in the range of 0 to 9 (this finds all the one, two, three etc. digit page numbers).
- (^13) looks for the paragraph marker immediately following the page number. Note: When using wildcards you can’t use the usual ^p for the paragraph marker — you MUST use ^13 (the control code for a carriage return). See: http://office.microsoft.com/en-us/word-help/find-and-replace-text-or-other-items-HA001230392.aspx#_Toc282602054
- ^p in the Replace field replaces everything found (the tab followed by the page number[s] followed by the paragraph mark) with a paragraph mark, effectively deleting the tab and page number(s).
It worked like a charm! My colleague was super impressed and I learned something new — can’t ask for more than that!
[Links last checked February 2012]