This article introduces how to use HeSoft Doc Batch Tool to batch extract specified text from Word document content and use it as a new file name. In the example, the original file name is an English subject name, while the header of each docx document contains a Document ID number. By customizing a regular expression to match the number, multiple Word files can be renamed to corresponding IDs at once, making it suitable for scenarios such as data archiving, exam paper numbering, contract numbering, and project document organization.
In daily office work, the real identifying information of many Word documents is not in the file name, but in the document body, header, cover, or fixed positions. For example, what you see in a folder is a batch of English title file names: Cosmic_Distances.docx, Galaxies_and_the_Milky_Way.docx, Planets_and_Orbits.docx, but after opening the documents, you discover there is a number more suitable for archiving in the header, such as 2JMM01G after Document ID. If there are only a few files, manually opening them, copying the number, returning to the folder, and renaming can be managed; but when the number of files reaches dozens, hundreds, or even more, this repetitive labor is very inefficient and prone to copying errors, missed changes, or accidental deletion of extensions.
The problem this article aims to solve is: how to use the batch processing capabilities in office software, through wildcards or regular expressions, to extract specified text from the content of Word documents and batch-set that text as the Word file name. Below, using HeSoft Doc Batch Tool as an example, it demonstrates the complete process of extracting the number following Document ID in a docx document and batch renaming Word files.
Applicable Scenarios: Which Word Files Are Suitable for Batch Renaming by Content
This method is suitable for all Word organization scenarios where "file names are non-standard, but the documents have stable identifiers internally." For instance, archive numbers in the headers of archival files, contract numbers at the beginning of contract texts, student IDs in exam papers or assignment documents, project codes on the covers of project materials, and course numbers in training materials. As long as this text has a relatively fixed format within each Word document, a regular expression can be used to match it and write the matched content into the file name.
Unlike common file name replacement tools, this process does not only handle existing file names; it reads the content of Word documents and then uses a segment of text from within the document for naming. Therefore, it is particularly suitable for the batch archiving of Word files like docx and doc. For office workers who need to maintain long-term databases, retrieve documents by number, and standardize naming conventions, this type of batch processing can significantly reduce repetitive work.
Effect Preview: File Name Changes Before and After Processing
Before processing, the Word file names in the folder are mainly document titles or topic names. While readable, such names are not necessarily suitable for archival management, especially when companies rely more on numbers, IDs, or codes to retrieve files, making the original file names not intuitive enough.

After opening one of the Word documents, you can see a fixed-format content section at the top of the page: the phrase Document ID followed by a string consisting of numbers and uppercase letters. The area highlighted by the red box in the screenshot is the target text source to be extracted in this article. In other words, we are not renaming arbitrarily but extracting the unique number already present in the Word content to serve as the file name.

After batch processing is completed, the original topic-type file names are replaced with the internal numbers from the documents, such as 2JMM01G.docx, 4HE73OR5.docx, CK83CAEJ.docx, etc. The extension is still preserved as docx, making it convenient to continue opening and editing with Word.

Operational Steps: Using Regular Expressions to Extract Word Content and Rename
Step One: Enter the File Name Tool and Choose to Rename Word Files Using File Content
After opening HeSoft Doc Batch Tool , select "File Name" in the left-side function category. The main interface will display multiple function cards related to batch file name processing, including finding and replacing keywords in file names, inserting text, adding prefixes and suffixes, etc. This article requires reading Word content for naming, so you should select "Rename Word Files Using File Content".

The purpose of this step is to enter the processing flow specifically designed for renaming based on Word file content. After selecting the correct function, the subsequent interface will guide you through adding files, setting matching rules, setting the save location, and starting processing in a wizard-like manner. For users unfamiliar with regular expressions, this step-by-step process can reduce the probability of operational errors.
Step Two: Add the Docx or Doc Files to be Processed
After entering the "Rename Word Files Using File Content" interface, you first arrive at "Select records to be processed". At the top of the page, you can see operation entries like "Add Files", "Import Files from Folder", "Clear", and "More". The example shows that 5 docx files have been imported, with the table displaying the serial number, name, path, extension, creation time, and modification time.

If you only need to process a small number of Word documents, you can click "Add Files" to select them individually; if the files are all concentrated in the same folder, you can use "Import Files from Folder" to add them all at once. After adding, you should focus on checking two points: first, whether the record count matches the number of files prepared for processing; second, whether the extension is the target Word format, such as docx. After confirming the list is correct, click "Next" at the bottom of the page.
The expected result of this step is: all Word files to be renamed appear in the software list, and their paths are correct. If you find files that should not be processed, you can remove them using the delete icon on the right side of the list to avoid mistakenly changing other document names.
Step Three: Set the Lookup Area to Text Matched by a Custom Formula
After entering "Set Processing Options", the interface provides a choice of lookup areas. The screenshot shows options like "First line text", "First barcode image", "Text matched by custom formula", and more. Since the target number in the example is located after Document ID, and the number format is relatively clear, select "Text matched by custom formula".
The significance of choosing this option is: the software will not simply take the first line, nor will it rely on a fixed position, but will search for text matching the rule you provided using the regular expression within the Word document content. As long as the format of Document ID is consistent across different documents, the batch process can extract each document's own number separately.
Step Four: Enter the Regular Expression to Match the Number Following Document ID
In the "Regular Expression" input box, the example rule filled in is:
(?<=Document ID:)[0-9A-Z]+

This expression can be understood by breaking it down: (?<=Document ID:) signifies matching only the content located after Document ID:, but not including Document ID: itself in the result; [0-9A-Z]+ means matching one or more digits or uppercase letters. Therefore, if the Word content contains Document ID:2JMM01G, the final text used for renaming will be 2JMM01G.
It should be noted that spaces, line breaks, or invisible symbols displayed in Word might affect the match. If your document contains Document - ID, DocumentID, Document ID: or a space after the colon, you will need to fine-tune the expression based on the actual text. For example, if there is a space after the colon, the rule can be adjusted to match the number following the space. The core principle is: the preceding fixed text is used for positioning, and the subsequent character range is used to extract the actual portion destined to become the file name.
Step Five: Choose the Write Location for the File Name
Further down the same page, you can see the "Position" options, including "Overwrite the entire filename", "To the left of the filename", "To the right of the filename". The example selects "Overwrite the entire filename", meaning the extracted Document ID will directly replace the original file name's main body, while the docx extension will continue to be retained.
If your goal is to use the number as the primary file name, for example, 2JMM01G.docx, choose "Overwrite the entire filename". If you wish to keep the original title and just append the number to the left or right, you can select "To the left of the filename" or "To the right of the filename" as needed. However, from the perspective of archiving standards, if the number is unique and more convenient for retrieval, overwriting the entire filename is usually more concise.
Step Six: Continue to Set the Save Location and Start Processing
After completing the matching rule and position settings, click "Next". As seen in the interface flow, the subsequent steps include "Set Save Location" and "Start Processing". It is recommended to prefer saving to a new folder before formal processing, or to ensure the original files have been backed up. This way, even if the regular expression settings do not meet expectations, you can quickly revert.
Once processing starts, the software will read the Word files in the list one by one, find the number after Document ID according to the regular expression, and then write the matched text into the file name. After processing is complete, return to the folder to see that the file names have been batch changed to the corresponding numbers.
Common Questions and Precautions
1. What if the Regular Expression Doesn't Match?
First, check if the fixed text in the Word content is exactly the same as the expression. For instance, the target in the screenshot is the number following Document ID. If the actual document has a Chinese colon, extra spaces, line breaks, or case differences, it might lead to a match failure. It is recommended to open a sample Word document first, copy the text near the target, and then adjust the expression based on the actual format.
2. What Happens if Document ID Appears in Multiple Places?
If the same format of Document ID appears in multiple places within one document, the software might pick one of those results depending on the matching rules. To avoid uncertainty, try to make the regular expression more precise, for example by combining fixed header text, number length, or preceding/following keywords to make the match result unique.
3. Can Both Doc and Docx Be Processed This Way?
The screenshot example processes docx files. For Word formats like doc, whether the content can be read depends on the current functional support of the software and the file's state. In practice, you can test with a small batch first before importing a large number of files. Whether it's doc or docx, it's recommended to close any currently open documents first to prevent file conflicts from affecting the renaming process.
4. Be Mindful of Illegal Characters in File Names
Windows file names cannot contain certain special characters. The number in the example only includes digits and uppercase letters, making it highly suitable for direct use as a file name. If you are extracting a contract name, title, or description text, you need to pay attention to whether it contains characters like slashes, colons, question marks, etc., that are unsuitable for file names.
Summary: Use Batch Processing to Reduce Repetitive Work in Word Renaming
Using the "Rename Word Files Using File Content" feature of HeSoft Doc Batch Tool , you can batch-extract numbers, IDs, archive numbers, and other text from inside Word documents and automatically write them into the file names. Compared to manually opening docx files one by one to copy and paste, this method is much more suitable for organizing large volumes of files and also reduces human error.
If your Word file names are chaotic, but the document content contains stable numbers or key fields, it is recommended to first select a few sample documents to confirm the text pattern, then establish a matching rule using a regular expression, and finally execute it in batch. This can transform a time-consuming file renaming task into a standardized process, making document archiving, retrieval, and handover more efficient.