Skip to content

Text Replacements

Text replacements are rules that automatically clean up, normalize, or modify your Markdown. They’re perfect for removing tracking parameters, fixing formatting, or standardizing content.

A text replacement rule has three parts:

  1. Pattern: The text or regex to find
  2. Replacement: What to replace it with (can include regex groups)
  3. Scope: Where the rule applies (entire content, selection, full page, or specific links)

Rules run in order from top to bottom. Each rule is processed independently, so order matters when rules interact.

Copymarky applies replacements at two stages:

Pre-Replacement (Before Markdown Conversion)

Section titled “Pre-Replacement (Before Markdown Conversion)”

Applied to the HTML before converting to Markdown. Useful for:

  • Removing unwanted HTML elements (ads, trackers, navigation)
  • Fixing broken source HTML
  • Stripping attributes that will clutter the Markdown
  • Removing entire sections (like comments or sidebars)

Example: Remove ads before conversion

  • Pattern: <div class="advertisement">.*?</div>
  • Regex: ✓ Enabled

Post-Replacement (After Markdown Conversion)

Section titled “Post-Replacement (After Markdown Conversion)”

Applied to the generated Markdown. Useful for:

  • Cleaning up extra spaces or formatting
  • Removing or normalizing URLs
  • Standardizing heading levels
  • Fixing link syntax

Example: Remove tracking parameters from URLs

  • Pattern: \?utm_[^&]*&?
  • Replacement: ?
  • Regex: ✓ Enabled

When creating or editing a replacement rule, you’ll configure:

The text or regex pattern to match. Examples:

  • Literal text: Copyright © 2024
  • Simple pattern: \s+ (one or more spaces)
  • Complex regex: \[source\]\(.*?\) (matches source links)

What to replace the pattern with:

  • Empty string "" to remove content
  • Plain text: Copyright © 2025
  • Regex groups: $1 - $2 (if pattern uses capture groups)
  • Off: Treat the pattern as literal text (exact match only)
  • On: Use regular expressions for advanced pattern matching

Use regex for flexible patterns like “any number,” “optional space,” or “capture and reorder text.”

Where the rule applies:

  • All content: Every part of the page
  • Selection only: Only the content you picked with the element picker
  • Full page: Entire page source (before element picker is applied)
  • Specific links: Only within links and URLs

Choose based on where you want the rule to apply.

  • ✓ Checked: Rule is active and will be applied
  • ○ Unchecked: Rule is disabled but not deleted; re-enable anytime

Toggle on/off to test rules without deleting them.


Example 1: Remove Tracking Parameters from URLs

Section titled “Example 1: Remove Tracking Parameters from URLs”

Problem: URLs contain UTM parameters that clutter your notes.

Rule:

  • Pattern: \?utm_[^&]*&?
  • Replacement: (empty)
  • Regex: ✓ Enabled
  • Scope: All content

Explanation: Matches ?utm_ followed by any characters until &, and removes it.

Before: [Read Article](https://example.com/article?utm_source=twitter&utm_campaign=organic&other=param)

After: [Read Article](https://example.com/article?other=param)


Example 2: Remove Site-Specific Ads or Navigation

Section titled “Example 2: Remove Site-Specific Ads or Navigation”

Problem: Repetitive “Advertisement” or “Related Articles” sections pollute every page.

Rule (Pre-Replacement):

  • Pattern: Advertisement
  • Replacement: (empty)
  • Regex: ○ Disabled (literal match)
  • Scope: All content

Explanation: Removes any occurrence of the word “Advertisement.”

Before:

# Article Title
Advertisement
Great article content here.
Advertisement

After:

# Article Title
Great article content here.

Problem: The page has too many ## headings; you want them as #.

Rule (Post-Replacement):

  • Pattern: ^##
  • Replacement: #
  • Regex: ✓ Enabled
  • Scope: All content

Explanation: Matches ## at the start of a line and replaces with #.

Before:

## Section One
## Section Two
## Section Three

After:

# Section One
# Section Two
# Section Three

Example 4: Extract and Reorder Text with Capture Groups

Section titled “Example 4: Extract and Reorder Text with Capture Groups”

Problem: Links are written as “Text (https://example.com)” but you want “Text”.

Rule (Post-Replacement):

  • Pattern: ([^\(]+)\s*\(([^\)]+)\)
  • Replacement: [$1]($2)
  • Regex: ✓ Enabled
  • Scope: All content

Explanation: Captures text and URL, then reorders them into Markdown link format.

Before: Click here (https://example.com) for more info

After: Click [here](https://example.com) for more info


Rules run top-to-bottom. If multiple rules could affect the same content, earlier rules run first.

Example: If you remove ad wrappers first, then remove “Advertisement” text, the second rule has nothing to match.

Before saving a complex rule:

  1. Test on a real webpage
  2. Review the output carefully
  3. Make sure you’re not accidentally removing content you want

Disable a rule temporarily to test if it’s causing issues. This is faster than deleting and recreating.

Broad patterns can unintentionally match content you want to keep.

Good: \?utm_source= — specific to UTM parameters

Risky: \? — could match any URL with a query string

Copymarky doesn’t support comments in rules, so name them clearly:

  • ✓ “Remove tracking params”
  • ✗ “Cleanup 1”

For complex patterns, test your regex online (e.g., regex101.com) before adding it to Copymarky.


Use CaseTypePatternReplacement
Remove tracking paramsPost\?utm_[^&]*&?(empty)
Normalize spacingPost\s{2,}
Remove brackets around URLsPost\[([^\]]+)\]\([$1](
Strip HTML commentsPre<!--.*?-->(empty)
Remove newsletter signupsPre(class|id)="newsletter.*?"(empty)