Phase 4 ยท Reference Material
Regex Library
Phase 4 extends the Regex Library with reusable, redacted text-cleanup and validation patterns collected from prior technical work.
Filename Cleanup HTML Cleanup Placeholder Replacement Text Cleanup URL Checks XML/Text Cleanup
Text Cleanup JavaScript
Replace CR/LF with Space
Flattens multiline text into one line while preserving word spacing.
Copy CurrentText = CurrentText.replace(/[\r\n]+/g, " ");
When to use
Use when MailOut, email subject, or text output should not contain line breaks.
Notes
Forgetting the global flag only affects the first match.
Text Cleanup JavaScript
Remove All Whitespace
Removes spaces, tabs, carriage returns, and line feeds.
Copy CurrentText = CurrentText.replace(/\s+/g, "");
When to use
Useful for Base64 strings copied from XML or wrapped text fields.
Notes
Do not use this when normal spaces must be preserved.
Text Cleanup JavaScript
Collapse Multiple Spaces
Converts repeated whitespace to a single space and trims ends.
Copy CurrentText = CurrentText.replace(/\s+/g, " ").trim();
When to use
Use after removing HTML tags or merging multiple fields.
Notes
This converts line breaks to spaces.
HTML Cleanup JavaScript
Replace Paragraph Tags with New Lines
Converts HTML paragraph endings to line breaks, then removes opening paragraph tags.
Copy CurrentText = CurrentText
.replace(/<\/p>/gi, "\n")
.replace(/<p[^>]*>/gi, "");
When to use
Use when converting simple HTML body text into plain text.
Notes
Order matters: handle closing tags before stripping all tags.
HTML Cleanup JavaScript
Replace Non-breaking Spaces
Converts HTML non-breaking spaces to normal spaces.
Copy CurrentText = CurrentText.replace(/ /gi, " ");
When to use
Use when HTML text displays extra blank content in output.
Notes
Some sources may encode this as   instead.
HTML Cleanup JavaScript
Strip All HTML Tags
Removes tags but keeps the text inside the tags.
Copy CurrentText = CurrentText.replace(/<[^>]+>/g, "");
When to use
Use only for simple HTML cleanup when the actual tag structure is not needed.
Notes
This is not a full HTML parser; use carefully on complex HTML.
Placeholder Replacement JavaScript
Replace {{OrderNum}} Placeholder
Escapes curly braces and replaces a placeholder with a JobInfo value.
Copy CurrentText = CurrentText.replace(/\{\{OrderNum\}\}/g, job.getJobInfo("OrderNum"));
When to use
Use for simple mail body templates with placeholder tokens.
Notes
Escape each brace when using a regex literal.
URL Checks JavaScript
Detect Existing HTTP/HTTPS
Checks whether a URL starts with http:// or https://.
Copy /^https?:\/\//i.test(url)
When to use
Use before prepending https:// to a URL from JobInfo.
Notes
The i flag makes the check case-insensitive.
Filename Cleanup JavaScript
Remove Illegal Filename Characters
Replaces characters that are unsafe in Windows-style filenames.
Copy CurrentText = CurrentText.replace(/[\\/:*?"<>|]+/g, "_");
When to use
Use before setting dynamic output filenames.
Notes
Still validate length and reserved device names separately.
XML/Text Cleanup JavaScript
Remove XML Namespace Declarations
Removes xmlns declarations from raw XML text when a namespace-free sample is needed.
Copy CurrentText = CurrentText.replace(/\s+xmlns(:\w+)?="[^"]*"/g, "");
When to use
Use only for documentation or controlled cleanup scenarios.
Notes
Do not remove namespaces if downstream XPath relies on them.
Related Topics
Phase 5 adds related-topic guidance to reduce duplicate entries and make reusable patterns easier to find.
Redacted Reviewed Canonical