This article describes how to use HeSoft Doc Batch Tool to batch extract specified text from the body of multiple Word documents and use it as the new file name. In the example, the docx file originally named with English titles contains a Document ID at the top of the body. By matching this number with a regular expression, the file name can be changed to formats like 2JMM01GJ, 4HE73OR5 in one go, suitable for scenarios where contracts, reports, archives, exam papers, etc., need to be archived by internal number.
When organizing a large number of Word documents, the true identifying information for many files isn't in the filename but is written in the body, header, cover page, or at the beginning of the document. For example, a batch of docx files originally named Cosmic_Distances.docx, Galaxies_and_the_Milky_Way.docx might look like regular titles, but each has a Document ID at the top of the Word body that is more suitable for archiving. If you manually open each Word file, copy the ID, close the document, and return to the folder to rename it, managing a few dozen files might be barely manageable, but hundreds of doc or docx files become a very repetitive and error-prone task.
The problem this article aims to solve is: using wildcards or regular expressions to batch-match specified text from Word document content, and using the matched results to rename that Word file. Below, using HeSoft Doc Batch Tool as an example, we demonstrate how to extract the Document ID from the Word body and batch replace the original filenames, achieving automatic naming based on document content.
Applicable Scenarios: Which Word files are suitable for batch renaming using body content
This method is particularly suitable for materials where filenames are irregular, but the document interior has a fixed number, fixed field, or fixed-format text. For instance, a project number at the top of a project report body, a contract number on the first page, a student ID in a student assignment, a sample number in a test report, or a document ID in archival materials. As long as this information is written relatively consistently across multiple Word files, it can be batch-extracted using regular expressions.
From the screenshot example, before processing there are 5 Word documents in the folder, with filenames that are English topic titles and a docx extension. Although they express the content theme, they are not conducive to searching, archiving, or system import by internal number. If business requirements mandate that the filename must equal the document number, manual renaming is very tedious.

After opening one of the Word documents, you can see a line of text at the top of the page: Document ID: 2JMM01GJ. Here, 2JMM01GJ is the content we want to extract and use as the filename. Since the ID consists of uppercase letters and numbers and is located after "Document ID:", it is very suitable for matching with a regular expression.

Result Preview: How filenames change after processing
Before processing, the filenames are Cosmic_Distances.docx, Galaxies_and_the_Milky_Way.docx, Planets_and_Orbits.docx, Stars_and_Life_Cycles.docx, and The_Expanding_Universe.docx. These names are suitable for reading, but if the subsequent workflow requires uploading by document ID, archiving by number, or comparing by number, manual searching is necessary again.
After processing, HeSoft Doc Batch Tool will batch-generate new filenames based on the IDs matched in each Word body. The 5 docx files in the example are renamed to 2JMM01GJ.docx, 4HE73OR5.docx, CK83CAEJ.docx, KR8IHZD6.docx, and R6J2S6E6.docx. The extension remains docx; what changes is the main filename.

The key value of this result is: you don't need to open Word to copy content one by one, nor rename them individually in File Explorer. As long as the rules are set correctly, the software can batch-read Word file contents, batch-match text, and batch-complete file renaming, thereby reducing repetitive labor and human input errors.
Step 1: Access the File Name tool and select the Word Content Rename feature
After opening HeSoft Doc Batch Tool , you can see modules like File Name, Folder Name, File Arrangement, Word Tools, Excel Tools, PowerPoint Tools, PDF Tools, etc., in the left-side tool categories. Since the goal this time is to modify filenames, first enter the File Name category on the left.
In the file name related feature list, select "Rename Word files using file content". The feature card description in the screenshot says it batch-uses certain text from Word file content as the filename for that file, which perfectly matches the need of this article: extracting the Document ID from the Word body and using it to replace the original filename.

The purpose of this step is to enter the correct batch processing function entry. Many users mistakenly think they first need to find and replace in Word or use File Explorer for batch renaming, but if the naming basis comes from the document content, ordinary filename replacement tools usually cannot read the body. Choosing the specialized Word content renaming feature here allows the software to read text within docx documents.
Step 2: Add the Word files that need batch processing
After entering the "Rename Word files using file content" interface, you can see action buttons like Add File, Import Files from Folder, Clear, More, etc., at the top. The middle area is the pending file list, which is a table listing information such as Index, Name, Path, Extension, Creation Date, Modification Date, and Actions.
If processing only a small number of specified files, you can click Add File; if a folder contains all the Word documents you need to process uniformly, you can use Import Files from Folder. The screenshot shows 5 docx files have been imported, located in the D drive test directory, with a record count of 5.

The expected result of this step is that all the Word files to be renamed appear in the list. It is recommended to check the file count, file extensions, and paths are correct before proceeding to the next step. For Word files, common extensions include docx and doc. The screenshot example is all docx, so the regular expression extraction and renaming will be executed for these imported records.
If the list includes files that do not need processing, you can remove a single record using the delete icon in the action column; if an import is wrong, you can also Clear and re-add. This prevents unrelated files from being renamed together.
Step 3: Set the search area to text matched by a custom formula
After clicking Next at the bottom, you enter the Set Processing Options interface. This screen shows you are currently at Step 2, mainly configuring the search area, regular expression, and filename position. Since we are not simply taking the first line of text, nor the first barcode image, but extracting the ID after "Document ID:", you should select "Text matched by custom formula".

After selecting "Text matched by custom formula", fill in the matching rule in the regular expression input box. The expression in the screenshot is:
(?<=Document ID:)[0-9A-Z]+
This expression can be understood as: find the continuous text consisting of digits 0-9 and uppercase letters A-Z that immediately follows "Document ID:". The preceding (?<=Document ID:) is a positive lookbehind assertion used to limit the matching position; the following [0-9A-Z]+ indicates matching one or more digits or uppercase letters. The final content used as the filename is the ID itself, such as 2JMM01GJ, not the entire text "Document ID:".
If the field format in your Word documents differs, you need to adjust the expression according to the actual content. For example, if the field is "Number: ABC123", the rule cannot simply copy "Document ID:"; if the number contains lowercase letters or hyphens, you also need to expand the character range. The focus of this article's example is not fixed on a specific ID, but on using regular expressions to precisely match target text in the Word body.
Step 4: Choose to Overwrite the entire filename
In the lower part of the same "Set Processing Options" interface, you can see position options, including Overwrite the entire filename, On the left of the filename, On the right of the filename. The screenshot shows "Overwrite the entire filename" is selected.
The meaning of "Overwrite the entire filename" is: the matched Document ID will directly replace the original main filename. For example, after Cosmic_Distances.docx matches to 2JMM01GJ, the new filename will become 2JMM01GJ.docx. The file extension .docx will not become part of the ID due to this setting; the original extension is typically preserved.
If your business only wants to add the ID before the original filename, you can choose "On the left of the filename"; if you want to keep the original title and append the ID at the end, you can choose "On the right of the filename". However, the goal of this example is to archive entirely by document ID, so choosing "Overwrite the entire filename" is the most direct.
Step 5: Proceed to set the save location and start processing
After completing the regular expression and position settings, click Next. The progress bar at the top of the interface shows that the subsequent stages are Set Save Location and Start Processing. The save location setting is used to determine where the processing results are output, and the specific choice can be based on actual work habits. For safety, before batch renaming, it is recommended to prioritize using a separate output directory or backing up the original files in advance to avoid affecting source materials if the rules don't meet expectations.
After entering the "Start Processing" stage, confirm that the number of pending files, naming rules, and save location are correct, then execute the processing. The software will read the content of the Word files in the list one by one, find the matching text according to the regular expression, and generate a new filename based on the position option. After processing is complete, return to the folder and you will see the filenames have been batch-changed from English titles to document IDs.
Explanation of Regular Expression Syntax: Why it can match the number after Document ID
In this case, the fixed field at the top of the Word page is "Document ID:", and the variable part is the subsequent ID. The regular expression uses the fixed field to locate the position and then extracts the variable part, which is a very common approach in batch naming.
(?<=Document ID:) means it only matches content located after "Document ID:" but does not include "Document ID:" itself in the result. [0-9A-Z]+ means the ID consists only of uppercase letters and digits, and its length can be one or more characters. By combining these two, the software can obtain a different ID from each Word document.
If the match result is empty, there are usually three aspects to check: first, whether the actual field in Word is consistent with the expression, for example, whether the colon is an English colon or a Chinese colon; second, whether there is a space after the field, and if so, you might need to include whitespace character matching in the expression; third, whether the ID contains lowercase letters, underscores, or other symbols. The closer the regular expression fits the actual text, the more stable the batch renaming results will be.
Common Questions and Notes
1. Do I need to close Word documents before processing? It is recommended to close the Word files being processed. When a file is occupied by Word, the batch processing software may not be able to read or write normally; closing documents reduces the probability of failure.
2. Can both doc and docx be processed using this idea? The screenshot example in this article uses docx files. For other Word formats, such as doc files, whether they can be processed depends on the actual import and recognition results of the software. After adding files, you can first check the extensions in the list to confirm the files have been correctly added.
3. What if multiple documents match the same ID? Duplicate filenames should be avoided during batch renaming. Before processing, it is best to spot-check whether document IDs are unique. If duplicates may exist in the business context, consider not overwriting the entire filename, but adding the ID to the left or right of the filename to reduce the risk of name duplication.
4. What if the regular expression doesn't match anything? First open a sample Word document, confirm the exact wording of the target field, and then compare and modify the expression. For example, whether there is a space between Document and ID, whether there is a space after the colon, or whether the ID contains special characters, all can affect the match result.
5. Why not just use Word's Find function? Word's Find function only helps you locate content within a single document, it cannot directly apply the found content to filenames in a batch. The value of HeSoft Doc Batch Tool lies in connecting reading content, matching text, generating filenames, and batch processing within a single workflow.
Summary: Using content-driven file naming to reduce repetitive renaming work
When filenames and internal document IDs are inconsistent, manual renaming is often inefficient and error-prone. Using the "Rename Word files using file content" feature of HeSoft Doc Batch Tool , you can extract information like Document IDs, contract numbers, report numbers, or student IDs from the Word body and batch-generate standardized filenames.
The example in this article uses the regular expression (?<=Document ID:)[0-9A-Z]+ to match IDs in Word documents, selects "Overwrite the entire filename", and finally renames 5 docx files uniformly to ID-based names. For users who need to organize a large amount of Word, docx, or doc materials, this batch processing method can significantly reduce the repetitive operations of opening, copying, pasting, and renaming. It is recommended that you first test the rules with a small number of sample documents, confirm the results are correct, and then execute the batch processing on the entire folder.