How to batch replace numeric keywords in multiple TXT text files using regular expressions


Translation:EnglishFrançaisDeutschEspañol日本語한국어,Update Time:2026-07-03 07:00:19

Disclaimer: All images, text, and video content on the website are for reference only and may not be the latest, correct, or accurate. In case of any dispute, please refer to the actual experience effect!

When you need to uniformly replace a large number of numbers, codes, or keywords across multiple TXT text files, opening each file to find and replace them manually is not only time-consuming but also prone to omissions. This article uses the example of batch replacing numeric content in multiple txt files with AAA, and introduces how to use the "Find and replace keywords in text" feature in HeSoft Doc Batch Tool to perform fuzzy text searches through formulas, commonly known as wildcard or regular expression methods, to process multiple text files at once. It is suitable for scenarios such as data masking, template cleaning, log organization, and content standardization.

When organizing a large number of TXT text files, it is common to encounter situations where the same type of content needs to be uniformly replaced. For example, multiple texts may contain scattered numerical IDs, statistical values, distances, years, quantities, IDs, or other dynamic content. If you open each file individually and use the find-and-replace function in an editor, the process is not only repetitive but also prone to missing certain files or locations.

The problem this article aims to solve is: how to use rules like wildcards and regular expressions to batch find and replace keywords in many text files. In the example, we will uniformly replace all numbers in multiple txt files with AAA. Although the demonstration uses TXT plain text files, this approach is equally suitable for processing content such as log texts, exported data descriptions, article drafts, configuration notes, and batch-generated report files.

The office software used in this article is HeSoft Doc Batch Tool . Its positioning is not simply editing a single file, but rather oriented towards batch file processing, helping users reduce repetitive labor. For scenarios requiring the execution of the same find-and-replace rules across multiple text files, such tools are more efficient than manual individual processing and also help maintain consistent results.

Applicable Scenarios: When is it suitable to use regex for batch find-and-replace of TXT content?

If you only occasionally modify a single word in one txt file, an ordinary text editor will suffice. However, when the number of files increases, or the content to find is not a fixed word but a category of text with a pattern, using regular expressions for batch replacement is more suitable.

Common scenarios include:

  • Batch replace numbers: For example, replacing all numbers in articles, materials, and logs with a uniform placeholder for desensitization or templating.
  • Batch clean up identifiers: For example, order numbers, batch numbers, chapter numbers, serial numbers, etc., which may not have identical formats but all follow a certain pattern.
  • Batch replace variable keywords: Such as years, version numbers, prices, statistical values that appear differently across various files.
  • Batch process English or Chinese text: As long as the content is plain text and needs to be found and replaced according to a uniform rule, a similar process can be used.
  • Batch organize materials: For instance, scientific research materials, training materials, txt content exported from web pages, AI-generated text drafts, etc.

In this case, the folder before processing contains multiple txt files, including big_bang.txt, black_holes.txt, dark_energy.txt, dark_matter.txt, and galaxies.txt. They all belong to a batch of text materials; if you were to open and modify numerical content file by file, the workload would increase rapidly with the number of files.

image-Batch replacement with regular expressions,batch find and replace in TXT files,replace text content with wildcards,batch process text files

Effect Preview: Numbers scattered in text before processing, uniformly replaced with AAA after

Before Processing: Multiple numbers need to be uniformly identified

In the sample file black_holes.txt before processing, the main text contains several numbers, such as 10 and 30. These numbers appear in different sentences, and their positions are not fixed. Using a normal exact find operation would only target one specific number, for instance, only replacing 10, and could not cover all numbers in one go.

image-Batch replacement with regular expressions,batch find and replace in TXT files,replace text content with wildcards,batch process text files

This is precisely where the value of regular expressions lies. We don't need to specify each individual number like "10", "30", "5", or "100"; instead, we use a rule to represent "consecutive numerical digits". The rule used in the screenshot is \d+, which can be understood as finding one or more digit characters. This way, the software identifies all numerical segments based on the rule when processing the file.

After Processing: Numbers matching the rule are batch replaced

After processing is complete, opening black_holes.txt again reveals that the numbers originally in different positions have been uniformly replaced with AAA. For example, numbers indicating radius, mass, distance, etc., in the original text all became the same placeholder text.

image-Batch replacement with regular expressions,batch find and replace in TXT files,replace text content with wildcards,batch process text files

This effect demonstrates that batch replacement does not just replace a single fixed word, but rather identifies a category of content based on a rule. For tasks requiring batch desensitization, batch templating, or batch text standardization, this method can significantly reduce repetitive operations.

Operation Steps: Using HeSoft Doc Batch Tool to batch replace text keywords

Step 1: Enter Text Tools, select Find and Replace Keywords in Text

After opening HeSoft Doc Batch Tool , you can see multiple office file processing entries in the left-hand tool category, such as File Name, Folder Name, File Organization, Word Tools, Excel Tools, PowerPoint Tools, PDF Tools, Text Tools, etc. Since this case deals with TXT text content, select Text Tools on the left.

In the Text Tools list, click "Find and Replace Keywords in Text". The interface description indicates this function is used for batch finding and replacing keywords in text file content, which precisely meets the goal of this article.

image-Batch replacement with regular expressions,batch find and replace in TXT files,replace text content with wildcards,batch process text files

The purpose of this step is to enter the correct batch processing function module. Once inside, the software guides you through a step-by-step process to complete file selection, processing option settings, save location settings, and starting the process, reducing the probability of errors in batch operations.

Step 2: Add the TXT files to be processed

Upon entering the function page, the first step is "Select records to be processed". As seen in the screenshot, the top of the page provides two entry points: Add File and Import Files from Folder. For a small number of files, Add File can be used; if a batch of txt files are all in the same folder, importing files from a folder is recommended to add multiple files at once.

image-Batch replacement with regular expressions,batch find and replace in TXT files,replace text content with wildcards,batch process text files

In the example, 5 txt files have been imported, and the list displays information including sequence number, name, path, extension, creation time, modification time, and operations. The files include big_bang.txt, black_holes.txt, dark_energy.txt, dark_matter.txt, galaxies.txt, all with the txt extension. The summary area at the bottom shows a record count of 5, indicating that this batch will process 5 text files.

At this step, two key checks are needed: first, confirm the file list includes all txt files requiring processing; second, confirm that no unnecessary files have been mistakenly added. If there are records in the list that do not need processing, they can be removed via the delete icon in the operations column. After confirmation, click the Next Step button at the bottom of the page to proceed to processing option settings.

Step 3: Select formula-based fuzzy text search, enter the regular expression

In the second step, "Set Processing Options", you need to set the search method and replacement content. The screenshot shows two options in the "Search Method" area: Exact Text Search and Use Formula for Fuzzy Text Search. Since this case aims to find all numbers, not a single fixed number, Use Formula for Fuzzy Text Search should be selected.

image-Batch replacement with regular expressions,batch find and replace in TXT files,replace text content with wildcards,batch process text files

Next, enter the following in the "List of Keywords to Find" field on the left:

\d+

Here, \d+ is a common regular expression syntax used to match one or more consecutive digits. For example, 10, 30, 100, 26000, etc., can all be identified. Since numbers may vary across different files, using this rule is more suitable for batch processing than inputting each number individually.

Then, enter the following in the "List of Replacement Keywords" field on the right:

AAA

This means any content matching the rule in the left field will be replaced with AAA. The screenshot also shows directional buttons in the middle, used for mapping find items and replacement items between the left and right columns. For this case, only one rule set is needed: find \d+, replace with AAA.

If you wish to ignore letter casing, you can pay attention to the related settings in "Additional Options". However, this case searches for numbers, so the case option will not affect the number matching results. After completing the settings, click Next Step to continue.

Step 4: Set the save location and start processing

Following the process bar at the top of the interface, subsequent steps include "Set Save Location" and "Start Processing". Although the screenshots focus on the first two steps, it is reasonable to infer from the process bar that the software will prompt the user to set a save location for the processed files before executing the batch process.

When setting the save location, it is advisable not to directly overwrite the only original files, especially when using regular expression batch replacement for the first time. The processing results can be saved to a new folder; after confirming the replacement effect is correct, decide whether to apply it to the official files. This ensures that even if a rule is written incorrectly, the original text content is not irreversibly modified.

After completing the save location setting, enter the Start Processing step to execute the batch replacement. Once the processing is finished, you can open one of the files for spot-checking to confirm whether the numbers have been replaced with AAA as expected.

What does the regular expression \d+ mean, and why is it suitable for batch replacing numbers?

Many users find "regular expressions" complex, but in batch office scenarios, mastering just a few common patterns can solve a large number of repetitive problems. The \d+ used in this case is very representative:

  • \d: Represents a digit character, typically matching 0 to 9.
  • +: Indicates the preceding element occurs one or more times.
  • \d+: The combination means matching a consecutive segment of digits.

For example, when text contains "10 times", "30 kilometers", "100 solar masses", or "26,000 light-years", \d+ will identify the consecutive digit parts within them. Note that if numbers contain commas, decimal points, or other symbols, the matching effect can be affected by how the expression is written. In the screenshots for this case, 26,000 is seen replaced as AAA,AAA, indicating the digits on either side of the comma were recognized and replaced separately. In practice, rules should be designed according to your specific data format.

Frequently Asked Questions and Notes

1. Why not use Exact Text Search?

Exact search is suitable for replacing fixed content, like changing "black hole" to "black object". But if you need to replace all numbers, the specific numbers can be numerous; using exact search would require listing them one by one, which is inefficient and prone to omission. Regular or wildcard methods are more suitable for finding "a category of content".

2. Is a backup necessary before batch replacement?

A backup is recommended. The advantage of batch processing is changing many files at once, but this also means a rule mistake has a wider impact. You can copy a folder first, or choose a new output directory in the software's save location step.

3. Can leaving the replacement empty achieve deletion?

The right-side prompt in the screenshot says "Leave blank to delete", meaning if no content is entered in the replacement keyword list, it can be used to delete the matched text. Before actual use, it's advisable to test with a small number of files first to confirm the effect meets expectations.

4. Is this suitable for processing docx or doc files?

This article demonstrates batch find-and-replace in the TXT Text Tool. If processing Word documents, such as docx, doc files, you should primarily consult the software's Word Tools related functions. The content structure varies between different file formats, so the TXT processing flow cannot be simply equated with Word document processing.

5. Is a more complex rule always better?

No. Batch office processing emphasizes stability and verifiability. If a problem can be solved with a simple rule, don't write an overly complex expression. For example, for just replacing numbers, \d+ is already sufficiently straightforward; if you need to match decimals, comma-separated numbers, or identifier formats, expand the rule gradually from there.

Summary: Using batch processing tools to reduce repetitive find-and-replace work

Through the examples in this article, we can see that using the "Find and Replace Keywords in Text" function of HeSoft Doc Batch Tool , numbers in multiple TXT files can be replaced with AAA in one go based on a regular expression rule. The entire process involves selecting Text Tools, importing multiple txt files, setting up formula-based fuzzy text search, entering the find rule and replacement content, setting the save location, and starting the process.

For users who frequently handle large volumes of text materials, log files, documentation, or batch-exported content, regular expression batch replacement can significantly reduce repetitive labor. It is recommended to first test the rules with a small sample of files, confirm the processing results are correct, and then execute the batch process on the entire folder. This both enhances efficiency and ensures the accuracy and consistency of text content replacement.


Keyword:Batch replacement with regular expressions , batch find and replace in TXT files , replace text content with wildcards , batch process text files
Creation Time:2026-07-03 06:59:57

Disclaimer: All images, text, and video content on the website are for reference only and may not be the latest, correct, or accurate. In case of any dispute, please refer to the actual experience effect!

Related Articles

Don't see the feature you want?

Provide us with your feedback, and after evaluation, we will implement it for free!