h1

Word: Find a word surrounded by tags and make it bold

April 28, 2019

In a comment for this post (https://cybertext.wordpress.com/2011/06/20/word-replace-and-reformat-text-inside-square-brackets-using-wildcards/), Christopher asked how to replace a term surrounded by tags (e.g. [b]Whistle[/b]) so that the tags (the [b] and [/b] bits) are removed, the word is made bold, and a dash is added after the word (I’ve assumed an en dash).

Again, find and replace with wildcards come to the rescue. NOTE: The steps below will only replace single words, not two or more words within the tags.

  1. Press Ctrl+h to open the Find and Replace dialog.
  2. In the Find field, type: (\[b\])(<*>)(\[\/b\]) (it’s probably best to copy this as it’s easy to mistype it)
  3. In the Replace field, type: \2 ^= (Note: There are two spaces you need to type here: between the 2 and the ^, and after the =)
  4. While your cursor is in the Replace field, click Format, then Font, and choose Bold.
  5. Click Find Next. Assuming the word and its marks are selected correctly, click Replace.
  6. Repeat Step 5 until you’ve done them all. If you are confident you won’t break anything, click Replace All.

What this all means:

  • In the first Find element (surrounded by parentheses), you have to ‘escape’ the square brackets as they are special characters in a wildcard search. The escape character is \ and you have two square brackets, so therefore you have to type: (\[b\]) 
  • In the second Find element (surround by parentheses), < means the beginning of a word and > means the end of a word, with * representing any and all characters in that word. This is a single whole word only.
  • Just like in the first element, you have to escape the special characters in the third Find element with \. There are three of them to escape this time—two square brackets and a forward slash.
  • In the Replace, the \2 represents the second element (i.e. just the single word), which you’re replacing with itself. Next, there’s a space, followed by ^= which represents an en dash, followed by another space.
  • Finally (Step 4 above), you need to tell Word to bold the item you’re replacing.

Notes:

  • Depending on how the original words and tags were spaced, you may end up with two spaces after the en dash—a simple find for two spaces and replace with one space will sort those out.
  • Any words that have a space (or other non-letter character) immediately after the [b] tag or before the [/b] tag probably won’t be changed.
  • This only works for single words. If you have more than one word, you’ll either need a different find/replace, or, if there’s only a few, you can search for them after running this and fix them manually.

One comment

  1. Hello Rhonda,

    Thanks for this useful how-to.
    This replacement is also possible using Multiple Find & Replace tool in TransTools+ plug-in for Microsoft Word (http://www.translatortools.net/transtoolsplus-multiplereplace.html).

    Here are the parameters you need to use to create a search & replace expression:

    Mode: Regular expression (.NET)
    Find What: \[[bB]\](.+?)\[/[bB]\]
    Replace With: $1
    Apply specific formatting upon replacement: Bold – Yes
    Screenshot: http://prntscr.com/nj01wb

    Screenshot of Multiple Find and Replace pane after adding the search & replace expression:
    http://prntscr.com/nj0286

    Text before replacement:
    http://prntscr.com/nj02jc

    Text after replacement:
    http://prntscr.com/nj02qh

    Best regards,
    Stanislav Okhvat
    TransTools – Useful tools for every translator
    http://www.translatortools.net



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: