Batch Desensitization of TXT File Content: Use Regular Expressions to Uniformly Replace Numbers in Multiple Files with Placeholders


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

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!

In the process of data sharing, test data preparation, and text template organization, it is often necessary to uniformly replace numbers in multiple TXT files with placeholders. This article focuses on batch desensitization of TXT file content, demonstrating how to use the text tool of HeSoft Doc Batch Tool to import multiple TXT files through the "Find and Replace Text Keywords" function, select formula fuzzy text search, use \d+ to match numbers, and batch replace them with AAA. The article provides a before-and-after comparison, complete steps, and rule considerations.

Before sharing text materials with colleagues, clients, or external systems, many people first perform content masking. For instance, they replace numbers, codes, statistical values, distances, amounts, or other sensitive information with uniform placeholders. The challenge is that this information is often scattered across multiple TXT files, and the numbers in each file are different. Manually opening and replacing them one by one is not only time-consuming but also prone to omissions.

This article uses a typical requirement as an example: batch-replacing numeric content in multiple txt text files with AAA. Here, AAA can be understood as a placeholder; you can also replace it with text like ***, [Number], {num}, etc., according to your actual needs. The office software used in the example is HeSoft Doc Batch Tool , which is oriented toward batch processing of documents and files, making it suitable for solving problems involving repetitive operations on a large number of files.

The article will combine screenshots to explain the state before processing, the effect achieved after processing, and how to complete the operation step-by-step in the software. After reading, you can apply the same method to tasks like batch masking of TXT content, batch text keyword replacement, log file cleaning, and material templating.

Applicable Scenarios: Batch Masking, Batch Cleaning, and Batch Templating

In practical office work, TXT files often serve as intermediate data or lightweight documents. Their simple format facilitates cross-system transmission, but it also means that sensitive information might appear directly in plain text. When the number of files is large, batch processing becomes very necessary.

The following situations are all suitable for using the method in this article:

  • Masking before sharing materials: Replace numbers, codes, and statistical data in text uniformly to avoid exposing original information.
  • Preparing test samples: Replace real data with placeholders, retaining the text structure but hiding specific values.
  • Organizing teaching or training materials: Replace numbers from different cases uniformly, making it convenient to create generic templates.
  • Cleaning system logs: Logs may contain numeric information like IDs, timestamps, and quantities, which can be processed uniformly according to rules.
  • Processing multiple English txt materials: Even if the main text is in English, as long as the content to be replaced matches the rules, it can be processed in batches.

Compared to ordinary find-and-replace, the focus here is on batch replacement of "similar content." We are not just replacing a single fixed number but using regular expressions to describe all numbers, allowing the software to identify and process them automatically.

Effect Preview: More Intuitive with Before-and-After Comparison

Before Processing: Multiple Text Files Awaiting Unified Processing

As seen in the screenshot, a folder contains multiple txt files, including big_bang.txt, black_holes.txt, dark_energy.txt, dark_matter.txt, and galaxies.txt. All these files need the same set of find-and-replace rules applied.

image-Batch text desensitization,regular expression replacement for numbers,batch replacement of text keywords,batch text file processing tool

This way of organizing files is very common: files from the same project, topic, or batch export are placed in one directory. Manual processing requires opening them one by one; a batch processing tool can import multiple records at once and execute the task uniformly.

Before Processing: Numbers Scattered Within Text Paragraphs

After opening black_holes.txt, you can see multiple numbers appearing in the text. For example, the annotated 10 and 30 in the screenshot appear in different contexts. The actual file might contain even more numbers, such as mass ranges, distance values, etc.

image-Batch text desensitization,regular expression replacement for numbers,batch replacement of text keywords,batch text file processing tool

If you only use ordinary exact search, you must know every single number to replace. But in masking scenarios, we usually only care that "it is a number," not the specific value. Therefore, using regular expressions is more suitable.

After Processing: Number Positions Replaced with AAA Placeholder

After batch processing is complete, checking the same file again shows that the original number positions have become AAA. Multiple AAA instances are highlighted in the screenshot, indicating the software has completed the replacement according to the rules.

image-Batch text desensitization,regular expression replacement for numbers,batch replacement of text keywords,batch text file processing tool

This type of processing result is highly suitable for display, testing, and template creation after masking. The text structure is preserved, but the specific numbers are no longer directly exposed.

Operation Steps: Completing TXT Batch Replacement with HeSoft Doc Batch Tool

Step 1: Open the Text Tool and Select Find-and-Replace

After launching HeSoft Doc Batch Tool , select Text Tools in the left navigation panel. This software interface categorizes different types of office processing tasks, such as Word Tools, Excel Tools, PDF Tools, Image Tools, and Text Tools. Since the object of this processing is txt file content, you should enter the Text Tools category.

On the Text Tools page, select "Find and Replace Keywords in Text". The description on this function card in the screenshot reads: batch find and replace keywords in text file content, which meets the requirement of this "batch replace numbers with AAA" task.

image-Batch text desensitization,regular expression replacement for numbers,batch replacement of text keywords,batch text file processing tool

The expected outcome of this step is to enter the batch task wizard page, where you can subsequently add multiple text files and set replacement rules within the same task.

Step 2: Import Multiple TXT Files to Process

After entering the "Find and Replace Keywords in Text" page, first select the records you need to process. The top right of the interface provides Add File and Import Files from Folder. If your files are already gathered in a folder, importing from a folder is usually more time-saving.

image-Batch text desensitization,regular expression replacement for numbers,batch replacement of text keywords,batch text file processing tool

After importing, the table will list file names, paths, extensions, creation times, and modification times. In the example, there are 5 records, all with the .txt extension, and the summary at the bottom shows the record count as 5. Before processing, you should carefully confirm the list: are all the files that need processing included, and have unnecessary files been excluded?

If a file should not participate in this replacement, you can remove it using the delete icon in the operation column. After confirming everything is correct, click Next at the bottom to proceed to set processing options.

Step 3: Choose to Find Text Using Formula (Fuzzy)

In the second step, "Set Processing Options," the software offers search modes. The screenshot shows options for Exact Find Text or Use Formula to Find Text (Fuzzy). The goal this time is to replace all numbers, not a specific fixed number, so you need to select Use Formula to Find Text (Fuzzy).

image-Batch text desensitization,regular expression replacement for numbers,batch replacement of text keywords,batch text file processing tool

You can understand this option as searching according to expression rules. Whenever a section of text matches the rule, the software will identify it and perform the replacement. For batch masking, this is much more efficient than listing items one by one.

Step 4: Enter Find Keyword and Replacement Keyword

In the left "Keyword List to Find" enter:

\d+

In the right "Replacement Keyword List" enter:

AAA

Here, \d+ is used to match continuous digits, and AAA is the replacement placeholder. With this setup, the software will search all imported txt files for content matching the \d+ rule and replace them with AAA.

It's important to note that the left and right key lists should maintain a corresponding relationship. Each find rule on the left corresponds to the replacement content at the same position on the right. If setting up multiple rule groups, it's recommended to check line by line to avoid misalignment.

Step 5: Set Save Location and Execute Batch Processing

After completing the keyword settings, continue the page flow to Set Save Location. When batch processing files, it's advisable to choose a new output location first, avoiding direct overwriting of the original files. This allows for comparative checks after processing to confirm the results are correct.

Finally, proceed to the Start Processing step to execute the batch find-and-replace. After processing is finished, open the txt files in the output folder for random checks. If you see that the original numbers have been replaced by AAA, it means the task was executed successfully.

Key Rule Analysis: Why \d+ Can Achieve Number Masking

\d+ is the most important setting in this tutorial. It is a common regular expression syntax suitable for matching numeric content.

  • \d represents a digit character.
  • + means the preceding element appears one or more times.
  • \d+ represents a continuous sequence of digits, for example, 5, 10, 100, 26000.

In the processing results screenshot, you can see multiple numbers in the file were replaced with AAA. For ordinary integers, this rule is very straightforward. However, if the text contains numbers with commas, decimals, negative numbers, or units, \d+ might only match the digit parts. For instance, 26,000 might be split into 26 and 000 for processing, resulting in AAA,AAA. Therefore, it is recommended to test with a typical file first before formal batch processing.

Common Questions and Precautions

1. Will batch replacement modify all imported files?

The set rules will be applied to the files in the task list. Thus, you must confirm the scope when importing files. If you only want to process some files, do not import unrelated files from the entire folder into the task.

2. Can I replace numbers with something else?

Yes. AAA is used in the example only for demonstration. Based on your needs, you can set the replacement content to ***, [Hidden], NUMBER, or other placeholders.

3. What if I want to delete the numbers instead of replacing them?

As the prompt on the right side of the screenshot indicates, "Leaving it blank in the replacement keyword list means deletion." Therefore, if you wish to delete the matched numbers, you can leave the replacement content empty. However, deletion operations are more likely to affect text readability, so backing up first is recommended.

4. How to choose between Exact Find Text and Formula Find (Fuzzy) Text?

If you are replacing a fixed word or phrase, choosing Exact Find Text is simpler; if you are replacing a category of patterned content, such as all numbers, a specific type of code, or date format, you should choose Use Formula to Find Text (Fuzzy).

5. Can this be used for doc, docx, PDF, and other files?

The screenshots in this article show the TXT file processing workflow within Text Tools. For Word doc/docx files or PDF files, you should select the corresponding Word Tools or PDF Tools on the left side of the software based on the file type, avoiding mixing processing methods for different formats.

6. Why test before batch masking?

Regular expressions are highly efficient, but they might also match content not intended for replacement if the rule is too broad. Testing with a small sample first allows you to confirm the rule's accuracy before batch processing all files, effectively reducing risk.

Summary: Use Regex Batch Replacement for More Efficient TXT Masking

This article demonstrated how to use HeSoft Doc Batch Tool to batch replace numbers in multiple TXT files with AAA. The core steps include: entering Text Tools, selecting "Find and Replace Keywords in Text," importing multiple txt files, choosing Use Formula to Find Text (Fuzzy), entering \d+ as the find rule, entering AAA as the replacement content, then setting the save location and starting the process.

For users needing batch masking, batch cleaning, or batch creation of text templates, this method can significantly reduce repetitive labor. You don't need to search file by file, nor list all numbers in advance. Just define the content to be processed with rules, and let the office software complete the replacement in batches. It is recommended to start testing with a small number of files, confirm the results, and then process the complete folder, balancing both efficiency and accuracy.


Keyword:Batch text desensitization , regular expression replacement for numbers , batch replacement of text keywords , batch text file processing tool
Creation Time:2026-07-03 07:00:43

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!