WordPipe Search and Replace: Online Help
    Wildcards
 

Submit feedback on this topic 

Menus: File   Options   Help   Running WordPipe  Screens: Actions   Files to process   Options   Status dialog
Up

 

 

 

Set the Search Type to 'Use Wildcards', then type the wildcard character and any other text in the Find what box.


To find
Use this
wildcard

Examples
Any single character ? s?t finds "sat" and "set".
Any string of characters * s*d finds "sad" and "started".
One of the specified characters [ ] w[io]n finds "win" and "won".
Any single character in this range [-] [r-t]ight finds "right" and "sight". Ranges must be in ascending order.
Any single character except the characters inside the brackets [!] m[!a]st finds "mist" and "most", but not "mast".
Any single character except characters in the range inside the brackets [!x-z] t[!a-m]ck finds "tock" and "tuck", but not "tack" or "tick".
Exactly n occurrences of the previous character or expression {n} fe{2}d finds "feed" but not "fed".
At least n occurrences of the previous character or expression {n,} fe{1,}d finds "fed" and "feed".
From n to m occurrences of the previous character or expression {n,m} 10{1,3} finds "10", "100", and "1000".
One or more occurrences of the previous character or expression @ lo@t finds "lot" and "loot".
The beginning of a word < <(inter) finds "interesting" and "intercept", but not "splintered".
The end of a word > (in)> finds "in" and "within", but not "interesting".
?, *, [, ], {, }, (, ), @, <, > or any of the 'special' purpose characters above, precede them with backslash \   (hello) finds "hello",
\(hello\) find "(hello)"

Notes

  • Note: wildcard searches are case sensitive.
  • You can use parentheses to group the wildcard characters and text and to indicate the order of evaluation. For example, type <(pre)*(ed)> to find "presorted" and "prevented".
  • You can use the \n wildcard to search for an expression and then replace it with the rearranged expression. For example, type (Newton) (Christie) in the Find what box and \2 \1 in the Replace with box. Word will find "Newton Christie" and replace it with "Christie Newton".

Example 1: Transpose first name and surname

There are many occasions when you are presented with blocks of text or numbers etc., where the order of the text is not what you might require in the final document. Swapping the placement of forename and surname as above is one such example – and don't forget you can add to the replacement, even when using bracketed replacements

For instance, you may wish John Smith to appear as Smith, John.

Or, more likely, you may have a column of names in a table, where you wish to exchange all the surnames with all the forenames.

John Smith
Brian Jones
Alan Williams

You could do them one at a time, but by replacing the names with wildcards, you can do the lot in one pass.

Let's then break up the names into logical sequences that can only represent the names:

At its simplest, we have here two words – John and Smith. They can be represented by<*>[space]<*> – where [space] represents a single press of the spacebar.
Add the round brackets (<*>)[space](<*>) and replace with \2[space]\1
Run the search on the column of names and all are swapped. Run it again and they are swapped back.

If some of the names contained middle names and/or initials

If some of the names contained middle names and/or initials, you would first have to convert your table to text (separated by paragraph marks). Select Table + Convert Table to Text.

Or if there is more than one column in your table, paste your Name column into a new document, and then convert that column to text.

You could then replace:
(<*) ([! ]@)^13

with:
\2, \1^p

This would convert:

John F. Kennedy
J. Smith
John Smith

  
to

Kennedy, John F.
Smith, J.
Smith, John
 
Finally, convert the text back to a table. (Select Table + Convert Text to Table).

If there was more than one column in your original table, then when converting the text back to a table, be sure to select Paragraphs, where it says Separate text at. Then, in your original table, delete the old column and paste in the new one.

Example 2: Transposing dates

Another useful example might be the changing of UK format dates to US format dates – or vice versa.

7th August 2001 to August 7, 2001

(For a similar example, see also Transpose dates from mm/dd/yy to yy/mm/dd.)

To give an example of how most of the wildcard characters could be used in one search sequence to find any UK date formatted as above, the following search pattern will do the trick:

[0-9]{1,2}[dhnrst]{2} <[AFJMNSOD]*> [0-9]{4}

Breaking it down:

[0-9] looks for any single digit number, but dates can have two numbers; so to restrict that to two, we use the count function {}. We want to find dates with 1 or 2 numbers so:
[0-9]{1,2}
Next bit is the ordinal th – Ordinals will be nd”, “st”, rd”, or th so identify those letters specifically:
[dhnrst]

There will always be two letters, so restrict the count to 2:
[dhnrst]{2}

Next comes the space. You can insert a space with the spacebar [space].
The month always begins with one of the following capital letters – AFJMNSOD. We don't know how many letters this month has so we can use the blanket * to represent the rest. And we are only interested in that word so we will tie it down with <> brackets:
<[AFJMNSOD]*>
There's another space [space] followed by the year. Years will always have four numbers so:
[0-9]{4}
Finally, add the round brackets to provide a logical break-up of the sequence:
([0-9]{1,2})([dhnrst]{2})[space](<[AFJMNSOD]*>)[space]([0-9]{4})

and replace with:
\3[space]\1,[space]\4

(where [space] represents pressing the spacebar once) to re-order the sequence.

US style manuals specify that ordinals should not be used in dates, but if you did want to keep the ordinals (so converting 7th August 2001 to August 7th, 2001), you could replace
([0-9]{1,2}[dhnrst]{2})[space](<[AFJMNSOD]*>)[space]([0-9]{4})

with:
\2[space]\1,[space]\3

You can use the same logic in reverse to convert August 7th, 2001 to 7th August 2001; or  to  convert August 7, 2001 to 7 August 2001. Unfortunately you can't add the ordinals using a  wildcard Find & Replace, if they're not there to begin with – you would need to use a macro if you wanted to do that. 

Example 3: Adding or removing the period in salutations

Assume you are parsing addresses and wish to separate the honorific from the name. American usage puts a period at the end (Mr., Mrs., Dr.) while British usage omits the period.

([DM][rs]{1,2})( )

will find Mr Ms Mrs Dr without the period and

\1.\2

will put one in.

or vice versa:

([DM][rs]{1,2}).

will find Mr. Ms. Mrs. Dr. with the period and

\1

will take it out.

Example 4: Duplicate paragraphs (and rows)

(*^13)\1\1 will match any sequence of three identical paragraphs.
If you replace:

(*^13)\1

with

\1

it will delete all consecutive duplicate paragraphs in the document. Repeat until nothing is found, to delete all duplicate paragraphs in the document (as long as you have sorted the text first).

Example 5: Tags

\<([!\<\>]@\>)*\</\1

will match any well-formed XML element including start-tag and end-tag such as:

<p>some text</p>

or 

<customer-name>John Smith</customer-name>

Replace any instance of the left square bracket character [ that happens to be the fifth character in a paragraph

In the Replace dialog box, click More, then check Use Wildcards and enter the following strings:

Find What:

(^13????)\[

Replace With:

\1

Tips for advanced users

You can paste any (Unicode) character (unfortunately not characters from decorative (Symbol) fonts) into your search expressions. So copying the first and last characters from the Greek or Cyrillic subsets into a search:


would match any Greek character:


matches any Cyrillic word:

(Can you help me please?)

Note: in Word 97, the characters sometimes display in the dialog box as squares, but they do work.

In Word 2000+, you can type in Unicode characters with the Alt-key (make sure NumLock is on, then hold down the Alt-key and type the numbers on the numeric keypad). Since all characters from decorative fonts (Symbol-, Wingdings-fonts ...) are kept in a special code page from &HF000 to &HF0FF, you can search for them with [Alt61472-Alt61695].
[a-c] will not only match a, b, c, but also:

[a-à] will not match all characters from U+0061 (a) to U+00E0 (à). 

For some discussion on Unicode sorting and wildcards see the Unicode Regular Expression Guidelines. In general, even if the sorting used in Word is not very transparent, you usually get the results you would expect.

Gremlins to be aware of (for advanced users)

  •  
Sometimes Word will get confused if it encounters escaped brackets \( or \). For example:
(\\)
will match any character, not only a backslash.

Workaround: use
([\\])
instead.

  •  
([a-z]\() throws an error – it should find an a(.

Workaround: Use ([a-z][\(]) instead.

  •  
Word starts matching again after the previous match/replacement; so for example ^13*^13 will match only every second paragraph in a Replace operation.

If that isn't what you want, you could (in this example) use *^13 instead. 

Other times, if this isn't what you want, you have to do multiple Find & Replaces. For example, supposing you wanted to subscript all the numbers in any chemical formula such as C2H4. You could tag the numbers that have to be subscripted; you want to subscript any group of numbers ([0-9]@) that follow a letter > ([A-Za-z]), and that are not followed by another number ([!0-9]): 

Find what: ([A-Za-z])([0-9]@)([!0-9])

Replace with: \1<sub>\2</sub>\3 

That search will for example match C2H in C2H4 (letter + number + non-number), and then continue searching after the H. So you need to run this replacement twice, before doing the Find and& Replace that applies the formatting.

But sometimes, Word finding every second instance of your search string may be what you want, and you can make use of the feature. (For instance, if you want to format the text between two identical tags).

  •  
Not a bug but still annoying: You have to escape any special character even if you type its code; so ^92 will have the same problems as typing the backslash.
  •  
The construction {0,} (find zero or more of the preceding item) is refused as incorrect syntax. This concept is available in Unix regular expression matching, so it's a curious omission.
  •  
You don’t always have to escape the special characters, if the context makes it clear that the special meaning isn’t wanted. [abc-] matches -, and [)(] matches ) or (. This may sometimes make your searches behave differently from what you expected.

 

 

 

 Contact Us   |  Support   |  Community
 Copyright © 2001-2009 DataMystic. All rights reserved.