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 CleanupHTML CleanupPlaceholder ReplacementText CleanupURL ChecksXML/Text Cleanup
Redacted samples: Sensitive names, URLs, IDs, customer values, infrastructure details, and project-specific values have been replaced with generic placeholders.

Replace CR/LF with Space

Flattens multiline text into one line while preserving word spacing.

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.

Remove All Whitespace

Removes spaces, tabs, carriage returns, and line feeds.

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.

Collapse Multiple Spaces

Converts repeated whitespace to a single space and trims ends.

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.

Replace Paragraph Tags with New Lines

Converts HTML paragraph endings to line breaks, then removes opening paragraph tags.

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.

Replace Non-breaking Spaces

Converts HTML non-breaking spaces to normal spaces.

CurrentText = CurrentText.replace(/&nbsp;/gi, " ");

When to use

Use when HTML text displays extra blank content in output.

Notes

Some sources may encode this as &#160; instead.

Strip All HTML Tags

Removes tags but keeps the text inside the tags.

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.

Replace {{OrderNum}} Placeholder

Escapes curly braces and replaces a placeholder with a JobInfo value.

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.

Detect Existing HTTP/HTTPS

Checks whether a URL starts with http:// or https://.

/^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.

Remove Illegal Filename Characters

Replaces characters that are unsafe in Windows-style filenames.

CurrentText = CurrentText.replace(/[\\/:*?"<>|]+/g, "_");

When to use

Use before setting dynamic output filenames.

Notes

Still validate length and reserved device names separately.

Remove XML Namespace Declarations

Removes xmlns declarations from raw XML text when a namespace-free sample is needed.

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.

RedactedReviewedCanonical