About This Article
This article was created using an automated generation workflow leveraging generative AI. It is based on official Microsoft documentation for REGEXEXTRACT and REGEXREPLACE, structured to extract and mask required items from dummy logs without using actual data.Verification Status: 📘 Microsoft Official Specifications Confirmed / Excel Hardware Not Tested
Using regular expression functions in Microsoft 365 Excel allows you to test preprocessing tasks directly in cells, such as "extracting only IDs" or "hiding email addresses," without moving logs to another tool. The key is not to write complex regular expressions from the start, but to check the results with a single dummy line and expand them one part at a time.
Try It First
Enter the following dummy log into A2.
2026-09-13 user=demo@example.com id=AB-123 ip=192.0.2.10 status=500
Enter the following formula into B2.
=REGEXEXTRACT(A2,"id=[A-Z]{2}-[0-9]{3}")
The expected result is as follows.
id=AB-123
Look Here
Breaking down the regular expression reveals its meaning.
| Part | Meaning |
|---|---|
id= | Literal id= |
[A-Z]{2} | Two uppercase English letters |
- | Hyphen |
[0-9]{3} | Three digits |
Microsoft's REGEX-related functions use PCRE2-compatible regular expressions. While regular expressions are powerful, attempting to create a universal pattern without defining the input format increases false positives.
Trying to Mask Email Addresses
Enter the following into C2.
=REGEXREPLACE(A2,"[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}","***@***")
demo@example.com is replaced with ***@***, while id=AB-123 and status=500 remain.
The important point here is to output conversion results to a separate cell without overwriting the original cell. During log investigation, keep the original data so you can compare it with the processed results.
Changing One Part
Change the ID in A2 to the following.
id=ABC-123
The initial formula will no longer retrieve it as expected. The reason is that [A-Z]{2} specifies "two uppercase letters."
If you also want to allow three characters, change only that part to the following.
=REGEXEXTRACT(A2,"id=[A-Z]{2,3}-[0-9]{3}")
{2,3} means "from 2 to 3 times."By changing one part and observing the difference in results, you can understand the meaning of quantifiers without memorizing regular expressions by rote.
Do Not Attempt to Completely Validate Email Correctness Using Regular Expressions
The pattern for emails used here is a learning exercise to "find and obscure strings that look like emails from dummy logs." It is not a formula for strictly validating every valid email address in the world.
Similarly, writing IP addresses as \d+\.\d+\.\d+\.\d+ will capture the format, but it will also capture 999.999.999.999.Extraction and validity checking are separate issues.
For Practical Work
Even office workers or support staff can use this for tasks such as the following:
Extracting only reception IDs from a list of logs received from the systems department
Masking email addresses before passing them to vendors or AI
Extracting only error codes into a separate column to aggregate counts
Picking up management numbers in a specific format from hundreds of lines of free text
However, production logs may also contain other sensitive information such as names, internal hostnames, URL query strings, and tokens. Do not assume it is safe just because email addresses were removed; have a human re-verify the converted output before sharing.

