This hidden feature of Google Docs makes Find & Replace much more powerful

Google Docs' Find & Replace is a useful tool, but a hidden feature can make it even more powerful: Regular Expressions.

When working with a large document, it's often helpful to quickly find specific text strings.

Maximize Find & Replace with RegEx

The ability to locate specific text within a document is valuable. Google Docs' Find & Replace feature enhances this capability by providing even more convenience. However, you can take your searching to the next level with Regular Expressions (RegEx). RegEx is a powerful tool that uses a string of characters to match patterns in text, allowing content to be found with incredible accuracy.

In Google Docs, you can use RegEx to refine your search process. While the standard Search feature only allows for fixed text searches, RegEx allows you to identify patterns, easily locating complex strings.

Unfortunately, Google Docs does not currently support replacing text with RegEx patterns. So, although you can use RegEx to find specific strings, they can only be replaced with fixed text.

Tip : Unlike Google Docs, Google Sheets provides REGEXREPLACE functionality, which allows searching and replacing text using RegEx, making this an extremely effective tool for Find & Replace in Google Sheets.

RegEx can save you significant time, especially when working with large documents. Since the RegEx option is not selected by default, it is easy to ignore. However, once you get used to its functionality, you'll find that RegEx is extremely simple and can become an invaluable part of your editing toolkit.

This hidden feature of Google Docs makes Find & Replace much more powerful Picture 1This hidden feature of Google Docs makes Find & Replace much more powerful Picture 1

To start using Find & Replace with RegEx in Google Docs, press Ctrl/Cmd + F to open the Find menu . Next, click the three vertical dots to open the Find & Replace window . Check the Use regular expressions box and you're done.

Tip : If you want, you can open the Find & Replace window with a single keyboard shortcut: Ctrl + H on Windows or Cmd + Shift + H on Mac.

Google Docs uses RE2 syntax for RegEx, and you can see the full syntax guide on the RE2 GitHub page for more detailed information. But if you're unfamiliar with RegEx, the following examples of common usage may help explain them.

Substitute more precise words

One of the common challenges with the standard Find & Replace feature is that it often replaces words within other words. For example, if you wanted to replace the word "bar" with "pub", you might accidentally change "bargain" to "pubgain" or "barbershop" to "pubbershop". This can lead to incorrect edits.

This hidden feature of Google Docs makes Find & Replace much more powerful Picture 2This hidden feature of Google Docs makes Find & Replace much more powerful Picture 2

This is where RegEx comes to the rescue. Using RegEx, you can specify that you only want to find the exact word "bar" and not instances where "bar" is part of a larger word. In RE2 RegEx syntax, b marks the boundary of a word, ensuring that the search is limited to the word itself, without affecting other words containing the same letters.

For this example, the following string will only find the word "bar":

b(bar)b

After entering this string, you can enter "pub" in the Replace with box and confidently click Replace all , knowing for sure that only exact matches of the word "bar" will be replaced.

This hidden feature of Google Docs makes Find & Replace much more powerful Picture 3This hidden feature of Google Docs makes Find & Replace much more powerful Picture 3

Remove citation number

Statements need citation numbers to inform readers where the information comes from and ensure its validity. However, if you cite from a website, you may not need these citation numbers because your text will not include a long reference page. In such cases, citation numbers can make the text look cluttered.

With RegEx, you can quickly remove these citation numbers in Google Docs, leaving only the text you need. Consider the text below:

This hidden feature of Google Docs makes Find & Replace much more powerful Picture 4This hidden feature of Google Docs makes Find & Replace much more powerful Picture 4

Deleting each citation number and parenthesis can be tedious. However, the RegEx string below can find all quote numbers at once:

[d+]

d+ indicates we are looking for one or more digits, and square brackets ([ ]) mean the digits will be within square brackets. From here, leave the Replace with box blank and click Replace all to remove the citation numbers.

This hidden feature of Google Docs makes Find & Replace much more powerful Picture 5This hidden feature of Google Docs makes Find & Replace much more powerful Picture 5

5 ★ | 2 Vote