Auto-redact sensitive terms in a Doc
Black out names, numbers, or any pattern from a Doc — a redaction pass over a list of terms.
Published Sep 28, 2025
When Northwind turns a client engagement into a public case study, the writing stays but the identifying detail has to go — client names, account numbers, and fee figures. Doing that by hand means scanning the Doc, finding every mention, and hoping nothing was missed. Miss one figure and a confidential deal is in the wild.
This script runs a redaction pass instead. You give it a Doc and a list of terms; it blacks out every one of them, plus any long number or pound figure it finds via pattern matching. Run it on a copy and you get a publishable version of the case study with the sensitive parts replaced by solid blocks.
What you’ll need
- A Google Doc to redact — ideally a copy of the original, since the script rewrites text in place.
- A list of the literal terms to remove: client names, project codenames, anything specific to the engagement.
- Nothing else. The number and currency patterns are built into the script.
The script
// The redaction marker that replaces every matched term.
const REDACTION_MARK = '████';
// Pattern: any run of 6 or more digits — account or reference numbers.
const LONG_NUMBER_PATTERN = '\\b\\d{6,}\\b';
// Pattern: a pound figure, with optional thousands separators and pence.
const CURRENCY_PATTERN = '£\\d+(?:,\\d{3})*(?:\\.\\d+)?';
/**
* Redacts a Doc in place: blacks out each literal term in `terms`,
* then any long number and any pound figure found by pattern.
*/
function redactDoc(docId, terms) {
const body = DocumentApp.openById(docId).getBody();
// 1. Replace each literal term — client names, codenames, etc.
for (const term of terms) {
body.replaceText(term, REDACTION_MARK);
}
// 2. Black out long numbers (account and reference numbers).
body.replaceText(LONG_NUMBER_PATTERN, REDACTION_MARK);
// 3. Black out pound figures, keeping the £ so the text still reads.
body.replaceText(CURRENCY_PATTERN, '£' + REDACTION_MARK);
}
/**
* Redacts a specific Northwind case-study Doc against its known
* sensitive terms. Edit the list and the ID for each new case study.
*/
function redactNorthwindStudio() {
const CASE_STUDY_ID = '1abcCaseStudyId';
const SENSITIVE_TERMS = ['Northwind & Co', 'AcmeCorp', 'Wagner Architects'];
redactDoc(CASE_STUDY_ID, SENSITIVE_TERMS);
Logger.log('Redaction pass complete.');
}
How it works
redactNorthwindStudioholds the things that change per case study — the Doc ID and the list of sensitive terms — and hands them toredactDoc.redactDocopens the Doc and gets itsbody, the element thatreplaceTextoperates on.- It loops the literal terms and replaces each one with the redaction marker.
replaceTextis case-sensitive, so list every spelling you care about. - It runs
replaceTextwithLONG_NUMBER_PATTERN, a regular expression that matches any run of six or more digits — account and reference numbers. - It runs
replaceTextwithCURRENCY_PATTERNto catch pound figures, replacing the digits but keeping the£so a redacted sentence still reads naturally. - All replacements happen directly in the Doc, so the file you point at is the file that gets redacted.
Example run
A paragraph in the original case-study Doc:
Northwind & Co delivered a brand refresh for AcmeCorp on account 4471203, a project valued at £42,500 over six months.
After running redactNorthwindStudio:
████ delivered a brand refresh for ████ on account ████, a project valued at £████ over six months.
The structure and story survive; every identifying detail is blacked out.
Run it
This is an on-demand job — run it once per Doc, against a copy:
- Make a copy of the original Doc (File → Make a copy) and use the copy’s ID. Never run this on the only copy you have.
- In
redactNorthwindStudio, setCASE_STUDY_IDand editSENSITIVE_TERMSfor the case study in hand. - Select
redactNorthwindStudioin the Apps Script editor and click Run. - Approve the authorisation prompt the first time, then open the Doc to check the result.
Watch out for
replaceTextmodifies the Doc in place — there is no undo from the script. Always run on a copy, never the original.- Matching is case-sensitive and literal. “AcmeCorp”, “Acme Corp”, and “ACME” are three different terms; list every variant you need to catch.
- The redaction is text-only. Numbers or names inside images, charts, or embedded drawings are not touched — check those by eye.
- The number pattern blacks out any run of six or more digits, including harmless ones like long dates or postcodes. Tighten the pattern if it is too greedy for your Doc.
- Redacted text is replaced, not visually covered. Someone with the original Doc can still see what was there — the protection comes from sharing the redacted copy and nothing else.
Related
Generate personalized study guides from notes
Reformat raw notes into structured study guides — for Northwind's internal training programme.
Updated Feb 8, 2026
Build a contract-clause assembly system
Construct Northwind agreements from a library of approved clauses — drag-drop in code.
Updated Feb 1, 2026
Translate and resolve Doc comments
Localise reviewer feedback on a shared Doc so multilingual teams can collaborate.
Updated Jan 25, 2026
Auto-archive finalized Docs to dated folders
File completed Northwind Docs by month so the active folder stays focused on in-flight work.
Updated Jan 18, 2026
Build a fillable intake form inside a Doc
Create structured intake forms with placeholder fields readers can fill — for client briefs.
Updated Jan 11, 2026