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


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

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 multiple TXT text files contain a large number of digits, serial numbers, dates, or variable keywords that need to be uniformly replaced, manually opening each file to find and replace is not only time-consuming but also prone to omissions. This article takes batch replacing consecutive digits in multiple text files with AAA as an example to introduce how to use the "Find and Replace Keywords in Text" feature in HeSoft Doc Batch Tool , using the regular expression \d+ to match digit content of varying lengths in one go and perform batch replacement, suitable for scenarios such as data cleaning, copy desensitization, log processing, and content standardization.

In daily office work, data organization, data cleaning, and pre-publishing content processing, many people encounter similar problems: a folder contains dozens or even hundreds of TXT text files, each scattered with different numbers, IDs, quantities, years, amounts, or other variable text. If you only need to replace one fixed word, a simple find-and-replace might suffice; but if you need to uniformly replace numbers of varying lengths like "10","30","100","26000" with the same content, manually opening and processing each file is highly inefficient.

The core problem this article addresses is: how to use wildcards or regular expressions to batch find keywords of different forms in multiple text files and replace them all at once with specified text. In the example, we will uniformly replace all consecutive numbers in multiple TXT files with "AAA". The software used for this operation is the office-oriented " HeSoft Doc Batch Tool ". Its value lies in batch processing files and reducing repetitive labor, making it especially suitable for office scenarios requiring frequent handling of txt files, text materials, log files, and exported document content.

Applicable Scenarios: Which Text Content is Suitable for Batch Replacement Using Regular Expressions

The advantage of batch find-and-replace using regular expressions is that it doesn't just match one fixed word, but can match a class of content based on rules. For instance, the \d+ used in this article can match one or more consecutive digits, so regardless of whether the text contains "5", "10", "30", "100", or the digit segments separated in "26,000", they can all be identified and replaced according to the rule.

This type of batch processing is suitable for the following scenarios:

  • Batch desensitization of text files: Uniformly replace numeric IDs and quantity information in TXT, log, and data files with placeholders.
  • Content standardization: Uniformly change variable numbers in multiple copies into fixed identifiers for subsequent proofreading or templated processing.
  • Batch cleaning of English materials: For example, when English popular science articles, documentation, and exported text contain a large number of numerical values that need to be uniformly replaced.
  • Processing program logs or configuration text: Content like port numbers, status codes, IDs, and count values in log files can be batch processed using rules.
  • Organizing a large number of TXT files: There's no need to open files like big_bang.txt, black_holes.txt, dark_energy.txt individually; you can execute operations uniformly on the file list directly within the software.

If your requirement is to batch replace content in Word documents, you can also extend this concept to doc, docx, and other document processing scenarios; however, the screenshots in this article show the batch find-and-replace process for TXT text file content under text tools, so the following explanation will focus on TXT files.

Effect Preview: Before Processing, Multiple TXT Files Contain Different Numbers

Before processing, multiple TXT text files have been prepared in the folder, including big_bang.txt, black_holes.txt, dark_energy.txt, dark_matter.txt, galaxies.txt, etc. The contents of these files are usually independent of each other. Manual processing would require opening each file sequentially and then performing find-and-replace, involving many repetitive steps.

image-Regex batch replacement,TXT batch search and replace,text file batch processing

Taking black_holes.txt as an example, the file body contains a lot of numerical content, such as "10", "30", "5", "100", "4", "26,000", etc. The red boxes in the screenshot highlight some of the numbers; it can be seen that these numbers vary in length and are scattered in location. Simply using a fixed keyword search can hardly cover all cases in one go.

image-Regex batch replacement,TXT batch search and replace,text file batch processing

This is exactly the scenario where regular expression batch replacement excels. We don't need to input each number like 10, 30, 100 separately; instead, we use one rule expression to match "all consecutive numbers". In the example, the rule is \d+, and the content replaced is "AAA".

Effect Preview: After Processing, Numbers are Uniformly Replaced with AAA

After completing the batch process, open black_holes.txt again to check. The original numeric positions in the body text have been replaced with "AAA". For example, positions where radius values, mass multiples, solar mass quantities, and distance values were previously located have all become the uniform placeholder text.

image-Regex batch replacement,TXT batch search and replace,text file batch processing

The effect screenshots demonstrate that batch replacement doesn't just process the single currently opened file; instead, it executes the same rules on multiple text files according to the task list. For office workers, this means that as long as the rules are set correctly, a large number of TXT files in an entire folder can be processed at once, significantly reducing the repetitive operations of opening, finding, replacing, and saving.

Operational Steps: Using HeSoft Doc Batch Tool to Batch Find and Replace

The complete operational flow is explained below according to the screenshot order. The key is understanding the purpose of each step: first select the function, then import files, next set the regular expression find rule and replacement content, and finally save and start processing.

Step 1: Enter "Text Tools" and Select "Find and Replace Keywords in Text"

After opening HeSoft Doc Batch Tool , select "Text Tools" from the left-side function categories. The main interface will display multiple batch processing functions related to text, such as Text to Word, Text to PDF, HTML to TXT, etc. The one used in this article is the first item: "Find and Replace Keywords in Text".

image-Regex batch replacement,TXT batch search and replace,text file batch processing

The purpose of this step is to enter the functional module specifically for batch finding and replacing text content. Unlike single-file find-and-replace in a regular editor, this function targets multiple text files, applying the same set of find-and-replace rules to the entire task list. Clicking this function leads to a wizard-style processing page.

Step 2: Add the TXT Files to be Processed

After entering the function page, the first step is "Select Records to Process". In the upper right area of the interface, you can see buttons like "Add File", "Import Files from Folder", "Clear", "More", etc. In the example, 5 TXT files have been imported, and the list shows the sequence number, name, path, extension, creation time, modification time, and an operation column.

image-Regex batch replacement,TXT batch search and replace,text file batch processing

If processing only a few files, "Add File" can be used; if the files are all in the same folder, it's more recommended to use "Import Files from Folder", which can add multiple TXT files to the list at once. After importing, check if the file names and paths are correct, and confirm that files that don't need processing can be deleted via the operation column. The bottom of the list shows "Record Count: 5", indicating the current task will process 5 text files.

The expected result of this step is: all TXT files with content to be replaced appear in the task list, with the extension txt and paths pointing to the correct file locations. Once confirmed, click "Next" at the bottom to enter the processing options settings.

Step 3: Select "Use Formula to Find Text Fuzzily"

On the "Set Processing Options" page, you can see the "Find Method" area. The interface provides two methods: "Find Text Exactly" and "Use Formula to Find Text Fuzzily". Since this article aims to match different numbers, not one specific fixed number, you need to select "Use Formula to Find Text Fuzzily".

image-Regex batch replacement,TXT batch search and replace,text file batch processing

The "Use Formula to Find Text Fuzzily" here can be understood as rule-based searching. For batch replacing numbers, IDs, and variable characters, it's more flexible than exact searching. An exact search is suitable for replacing fixed words, like changing "black hole" to "black hole"; whereas regular expressions or wildcard rules are suitable for matching a class of content, such as all numbers, specific format IDs, text between fixed prefixes and suffixes, etc.

Step 4: Enter the Regular Expression \d+ in the Keyword List

Enter \d+ in the "List of Keywords to Find" on the left. This expression means matching one or more consecutive digits. \d represents a digit character, and + means the preceding digit appears one or more times. Therefore, regardless of whether the text has 1-digit, 2-digit, or multi-digit numbers, they can all be hit by this rule.

For example, "10" and "30" appearing in the pre-processing screenshots both conform to the \d+ matching rule. Other digit segments like "5", "100", "4", "26", "000" in the body text will also be identified as consecutive digits. Note: If numbers contain commas, spaces, or other separators, consecutive digits will be matched separately based on the separator positions. You should confirm in advance whether this meets your expectations when setting up the replacement rule.

Step 5: Enter AAA in the Replaced Keyword List

Enter "AAA" in the "List of Replaced Keywords" on the right. This establishes a find-and-replace pair: replace the numeric content matched by the rule on the left with the specified text "AAA" on the right. The red boxes in the screenshot highlight the \d+ on the left and "AAA" on the right, indicating the rules have been set up.

If your actual needs differ, you can replace "AAA" with other content. For instance, it could be replaced by "***" for desensitization, "{number}" for templating, or "Number Placeholder" for placeholder proofreading. When setting this up, ensure the corresponding relationship between the left and right rules is clear to avoid misalignment across multiple rule rows.

Step 6: Proceed to the Next Step, Set the Save Location, and Start Processing

After completing the keyword option settings, click "Next" at the bottom. The interface flow also includes "Set Save Location" and "Start Processing" steps. It is recommended to choose an output directory that is clearly distinguishable when setting the save location to avoid mixing with original files and causing accidental overwrites or difficulties in traceability. After confirming the save location, proceed to the start processing step to execute the task.

The expected result of this step is: the software follows the imported file list, executes the same regular expression find-and-replace rule for each TXT file, and saves the processing results to the specified location. After the process is complete, you can open one of the files for spot-checking to confirm whether the numbers have been replaced with "AAA" as expected.

Common Questions and Precautions

1. Why use \d+ instead of entering 10, 30, 100 individually?

Because these numbers are not the same fixed keyword. Entering them individually would miss other numbers and is unsuitable for processing a large number of files. \d+ means matching consecutive digits, which can cover numeric content of various lengths at once, making it more suitable for batch replacement.

2. What is the difference between "Find Text Exactly" and "Use Formula to Find Text Fuzzily"?

"Find Text Exactly" is suitable for replacing fixed content, such as fixed words, fixed phrases, or fixed identifiers; "Use Formula to Find Text Fuzzily" is suitable for using rules to match a class of content, like numbers, IDs, or strings in a certain format. This article replaces all numbers, so the latter is chosen.

3. Do I need to back up the original files before batch processing?

It is recommended to keep a backup of the original files, or save the results in a new directory. If the rules for batch replacement are set incorrectly, it might affect not just one file but a whole batch. Following a workflow of backup first, processing next, and spot-checking last is a relatively prudent office practice.

4. Will replacing numbers affect the English body text?

The rule \d+ only matches digit characters and will not directly replace ordinary English letters. However, if the English body text contains numbers, such as years, quantities, distances, or IDs, these numbers will be replaced. You should confirm that all numbers need to be uniformly replaced before processing.

5. Can this be used for other formats, like doc, docx, or PDF?

The screenshots in this article show the batch find-and-replace process for TXT file content under "Text Tools." For Word doc, docx, or PDF files, you should select the appropriate function based on the corresponding Word tool, PDF tool, or other functional modules within the software. The file structures of different formats vary, and the entry points for operations and processing rules may not be identical.

Summary: Using Regular Expressions for Batch Replacement Turns Manual Text Processing into Rule-Based Processing

Through the examples in this article, it can be seen that faced with a large amount of numeric content in multiple TXT text files, there is no need to open files one by one, nor to input different numbers item by item. As long as you select "Find and Replace Keywords in Text" in HeSoft Doc Batch Tool , import the files to be processed, select "Use Formula to Find Text Fuzzily", enter \d+ as the find rule, and set the replacement content to "AAA", you can complete text replacement in batch.

The core value of this approach is delegating repetitive tasks to office software, transforming manual operations into rule-based processing. For those who frequently organize materials, clean TXT files, process logs, perform content desensitization, or batch modify copy, mastering wildcard and regular expression batch find-and-replace can significantly improve efficiency and reduce the risk of omissions. It is recommended that you first verify the rules with a small number of test files, and after confirming the results are correct, apply them to all text files in the complete folder.


Keyword:Regex batch replacement , TXT batch search and replace , text file batch processing
Creation Time:2026-07-03 07:02:31

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!