Thứ Sáu, Tháng Ba 7, 2025
spot_img
HomeFinanceThis hidden feature of Google Docs makes Find & Replace much more...

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

When working with a large document, it's often helpful to quickly find specific text strings. Google Docs' Find & Replace is a useful tool, but a hidden feature can make it even more powerful: Regular Expressions.

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.

Find & Replace in Google Docs
Find & Replace in Google Docs

To start using Find & Replace with RegEx in Google Docs, tap Ctrl/Cmd + F to open the menu Find. Next, click on the three vertical dots to open the window Find & Replace. Check the box Use regular expressions that's it.

Xem thêm  How to write mathematical symbols in Canva

Tips: 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.

A sample text with the Find & Replace dialog box in Google Docs
A sample text with the Find & Replace dialog box in Google Docs

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 box Replace with and click with confidence Replace allknowing for sure that only exact matches of the word “bar” will be replaced.

Find exact strings using RegEx Find & Replace in Google Docs
Find exact strings using RegEx Find & Replace in Google Docs

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.

Xem thêm  How to install Christmas theme for Messenger

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

Sample text with citation number in Google Docs
Sample text with citation number in Google Docs

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 ([ ]) means the digits will be in square brackets. From here, let's box Replace with blank and click Replace all to remove citation numbers.

Remove citation numbers using RegEx in Google Docs
Remove citation numbers using RegEx in Google Docs

Find duplicate words

Duplicate words often appear in our writing, especially after editing. Your brain tends to automatically ignore them, making it difficult to spot these errors when rereading. While a good grammar checker can spot duplicate words, you can also use RegEx in Google Docs to find them.

One of the cool features of RegEx is back-references, which allow the string to remember what it looked up for. You can use this to find consecutive duplicate words using RegEx:

\b(\w+)\s+\1\b

The above code marks the equal word boundary \bindicates an equal word \w+ and put the word in parentheses to create a capturing group so that the word can be referenced later. \s+ represents one or more space characters and \1 is a back-reference to the first group captured (which is the word itself).

Find duplicate words in Google Docs using Regex
Find duplicate words in Google Docs using Regex

In short, the RegEx string searches for a word, followed by a space, and then searches for the same word again. This effectively highlights all duplicate words in your document.

Note: If Google Docs supports RegEx instead, you can remove all those duplicate words in one step. So you'll need to find each word using RegEx, then delete each word individually.

Xem thêm  Telex typing method, Telex typing method and Vietnamese Telex code table

Clean up web links

URLs often come with unnecessary tracking parameters, making them long and unattractive. These parameters often help the website track information like how you found the page, whether you are logged in or not, etc. While you may be fine with this tracking, these additional parameters make for URLs that are longer than necessary.

A sample table in Google Docs that includes web links
A sample table in Google Docs that includes web links

RegEx can help clean up these URLs by removing everything after the question mark, which is typically where tracking parameters begin:

\?(.+)

The string begins with a question mark. The period (.) matches any character, and the plus sign (+) means one or more previous elements (in this case, any character). While the RegEx string successfully highlights unnecessary parameters in the URL, there is a small problem: If you have a sentence with a question mark that is actually used for punctuation, the RegEx string will also match the punctuation mark. that question.

Clean up web links with RegEx in Google Docs
Clean up web links with RegEx in Google Docs

To avoid this, you can adjust the RegEx string:

\?(?!\s)(.+)

In this series, ?! ​is a negative look-ahead assertion, ensuring that the character immediately following the question mark is not a space (\s). This will exclude actual questions from the form.

Now you can safely remove junk from the URL by replacing it with zero. With cleaner URLs, the table will be much less cluttered:

Neat URLs in Google Docs
Neat URLs in Google Docs

Warning: Make sure you check your final URLs to see if they still work!

These examples are just a few of the countless ways RegEx can help you in Google Docs. Although they may seem intimidating at first, RegEx is very simple once you get used to them. Start experimenting and you'll soon discover how much time and effort RegEx can save you.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments