Question: How can I automate a find & replace function to change the font colour of all suit symbols document wide?

I write bridge articles (card game), and I need to automate this formatting constantly:

Find all "♣" and color the text green (#00b700). Find all "♦" and color the text orange (#ff8100). Find all "♥" and color the text red (#ff0000). Find all "♠" and color the text blue (#0000ff).

**Answered:** Mark and Michael helped build Google Apps Scripts to do this (see below). [I modified the script and it's working perfectly](http://pastebin.com/3kZBVz2F).

Answer: 
To do a find-and-replace with formatting, you will need to use Google Apps Script. I am going to assume you are already familiar with GAS, but if not please reply with a comment on this post.

This script provides an example where you can change the background color of all 4 suits to the same color, by adding a menu to your document that will apply the formatting to all instances. Here is what the new menu will look like after adding the script to your Google Doc:

[![Utilities > Auto-Replace menu next to the "Help" menu in the Google Docs toolbar](https://i.stack.imgur.com/hrKMo.png)](https://i.stack.imgur.com/hrKMo.png)

And here is the code:

```
function onOpen() {
  DocumentApp.getUi()
      .createMenu('Utilities')
      .addItem('Auto-Replace', 'replaceSuits')
      .addToUi();
};

function replaceSuits() {
  var body = DocumentApp.getActiveDocument().getBody();      

  var found = body.findText("(♥|♦|♣|♠)");
  while (found) {
    var elem = found.getElement();
    if (found.isPartial()) {
      var start = found.getStartOffset();
      var end = found.getEndOffsetInclusive();
      elem.setBackgroundColor(start, end, "#ff0000");

    }
    else {
      elem.setBackgroundColor("#ff0000");
    }
    found = body.findText("(♥|♦|♣|♠)", found);
  }
};

```

This question is similar to [Formatting in replaceText()](https://stackoverflow.com/questions/50305428/formatting-in-replacetext), from which I borrowed code.

Here is a longer example which highlights each suit differently as described in your question (uses 4 separate code blocks for each suit, could definitely be refactored to allow shared code but this was the easiest way for me to code it): <https://pastebin.com/7Y1L6BqF>
Use the Reversible Formulas add-on for your next article.

In your doc, write for example:

> 
> c = (["♣", {color: "#00B700"}])  
> 
> d = (["♦", {color: "#FF8100"}])  
> 
> s = (["♠", {color: "#0000FF"}])  
> 
> h = (["♥", {color: "#FF0000"}])
> 
> 
> What can you do with =c =d =s and =h?
> =====================================
> 
> 
> One =h, with three =d =d =d vs. two =s =s and two =c =c.
> 
> 
> 

Click on "Display values", you'll obtain:

> 
> [![Rendered version of the code above](https://i.stack.imgur.com/dYvsd.png)](https://i.stack.imgur.com/dYvsd.png)
> 
> 
> 

To hide the definitions from the document, click on "Extract defs", they will be placed in a separated code box above.

> 
> [![Interface of Reversible Formulas - Sketch-n-Script](https://i.stack.imgur.com/x5MiG.png)](https://i.stack.imgur.com/x5MiG.png)
> 
> 
> 

If you don't remember which letter is which symbol, you can always click on one of the buttons on the sidebar to insert the code for a symbol. Just click on "Display" value so that it's replaced by the symbol itself.

The add-on can be found there:
<https://workspace.google.com/u/0/marketplace/app/spreadsheet_cells_in_javascript_fields_s/159836395898>

Disclaimer: I'm the author of this add-on