Skip to content

Snippets

Johan Sanneblad edited this page Aug 18, 2026 · 20 revisions

26 snippets. Last updated: 2026-08-18

Snippets are find and replace rules that run on everything you paste. A snippet can hold several rules, one per line, and find is a JavaScript regular expression. A # comment names the snippet:

# Name of the snippet
s/find/replace/flags
s/find/replace/flags

Copy any block below, open Settings → Better Paste → Custom processing → Snippets, and press Import snippets. Want to try a rule first? Open the Better Paste playground on regex101. In the examples, ⏎ marks a line break.


AI citations and references


Remove Perplexity citations

Perplexity has a copy button that strips citations, but it always copies the whole answer. Select part of it with the mouse instead and the citation markers come along. This removes them:

# Remove Perplexity citations

# Remove linked citations like [2](https://source)
s|\[\d+\]\(https?://[^)]*\)||g

# Remove plain citations like [1]
s/\[\d+\]//g

Before:

The sky appears blue because of Rayleigh scattering[1][2]. The same
effect turns sunsets red[3](https://example.com/source).

After:

The sky appears blue because of Rayleigh scattering. The same
effect turns sunsets red.

Keep the two rules in this order. A linked citation like [3](https://example.com/source) must be removed as a whole. With only the plain rule, [3] disappears and (https://example.com/source) stays in your note.


Remove source tags

Perplexity sometimes writes the source name instead of a number, like [wikipedia]. This removes those tags. Put the names you see between the parentheses, separated by |:

# Remove source tags like [wikipedia]
s/\[(wikipedia|reddit|youtube)\]//gi

fact[wikipedia] more[Reddit] donefact more done


Remove Perplexity export citations

Perplexity's markdown export uses scoped footnotes instead, like [^1_2], with a reference list at the end:

# Remove Perplexity export citations

# Remove citations like [^1_2]
s/\[\^\d+_\d+\]//g

# Remove the reference list at the end
s/^\[\^\d+_\d+\]:.*$\n?//gm

Qubits.[^1_2][^1_3] endQubits. end

text⏎[^1_3]: https://ex.com⏎tailtext⏎tail

From ckep1's Perplexity chat exporter.


Remove ChatGPT source markers

ChatGPT answers can carry source markers like 【35†source】:

# Remove ChatGPT source markers like 【35†source】
s/【[^【】]*†[^【】]*】//g

grew 12%【35†source】.grew 12%.

Based on patterns shared by Foxalabs and others on the OpenAI forum.


Remove ChatGPT reference tags

Answers that used web search sometimes leak internal reference tags into the copied text:

# Remove ChatGPT reference tags
s/:{0,2}contentReference\[oaicite:\d+\]\{index=\d+\}//g

Paris hosted them.:contentReference[oaicite:3]{index=3}Paris hosted them.

From fwerner13's normalize-chatgpt plugin.


Unwrap Google AI Overviews citations

Google AI Overviews wrap their citations in an extra pair of brackets, which Obsidian renders as a broken wikilink:

# Unwrap Google AI Overviews citations
s/^\[(\[\d+\]\(.+\))\]$/$1/gm

[[1](https://a.com), [2](https://b.org)][1](https://a.com), [2](https://b.org)

From dawni on the Obsidian forum.


Remove footnote markers

Academic text and markdown exports carry footnote markers like [^12]:

# Remove footnote markers like [^12]
s/\[\^\d{1,3}\]//g

disputed.[^12] Laterdisputed. Later

From gino_m on the Obsidian forum.


AI formatting


Remove bold from headings

ChatGPT loves bold headings like ## **Overview**. This unwraps them (one bold pair per heading):

# Remove bold from headings
s/^(#{1,6} .*?)(?<!\\)\*\*([^\n]*?)(?<!\\)\*\*/$1$2/gm

## **Overview**## Overview

From churnish on the Obsidian forum.


Convert ChatGPT math to dollar math

ChatGPT writes math as \( ... \) and \[ ... \], which Obsidian does not render. This converts both:

# Convert ChatGPT math to dollar math

# Block math to $$ ... $$
s/\\\[([\s\S]*?)\\\]/$$$$$1$$$$/g

# Inline math to $ ... $
s/\\\(([\s\S]*?)\\\)/$$$1$$/g

Energy \( E = mc^2 \) and \[x+y\]Energy $ E = mc^2 $ and $$x+y$$

The pattern comes from aqhours' Latex2MathJax and GoSlowPoke168's Clean AI Paste, two plugins built around exactly this conversion. The stacked dollar signs are on purpose: in a replacement, $$ produces one literal $.


Remove horizontal rule lines

LLMs sprinkle --- between sections. This deletes those lines:

# Remove horizontal rule lines
s/^[ \t]*---[ \t]*\n//gm

end.⏎---⏎## Nextend.⏎## Next

Two things to know: --- also fences frontmatter, and a --- directly under a line of text is a heading in Markdown. Both are rare in mid-answer copies, but check the result the first time. The idea comes from Lymnah's Linter rule with the motivation that separators are "frequently inserted by ChatGPT and other LLMs".


Remove emoji

This strips decorative emoji, the 🚀 and 🎯 kind that AI answers put in headings:

# Remove emoji
s/[ \t]*[\u{1F000}-\u{1FFFF}\u{2600}-\u{27BF}\u{2300}-\u{23FF}\u{2B00}-\u{2BFF}\u{FE0F}\u{200D}]+[ \t]*/ /gu

## 🚀 Getting started## Getting started

It can leave a space at a line end, so pair it with Remove spaces at line ends. From GoSlowPoke168's Clean AI Paste.


Links and images


Convert links to plain text

This turns every markdown link into plain text, keeping the label:

# Convert links to plain text
s/(?<!!)\[([^\]]+)\]\([^)]*\)/$1/g

See [the docs](https://ex.com) nowSee the docs now

Adapted from stiang's remove-markdown.


Replace images with their alt text

Same idea for images, keeping the alt text. Note that this removes the image before Better Paste can save it, so only use it where images are noise:

# Replace images with their alt text
s/!\[([^\]]*)\]\([^)]*\)/$1/g

![system overview](arch.png)system overview

Also from remove-markdown.


Remove empty links

Web copies often contain links with no text at all, like [](#anchor):

# Remove empty links
s/(?<!!)\[\]\([^)]*\)//g

Overview[](#_anchor) ofOverview of

Adapted from ratacat's slurp-ai scraper.


Remove anchor-only headings

Documentation pages carry invisible self-link headings that survive the HTML conversion:

# Remove anchor-only headings from web clips
s/^#{2,} \[\]\(.+#.+\)$\n+//gm

## [](https://site.com/docs#install)⏎## Install## Install

From siralmat in the Apply Patterns examples.


Shorten link labels that are bare addresses

When a link's text is just the address again, this shortens the label to the bare domain and path:

# Shorten link labels that are bare addresses
s|\[(https?://)?(www\.)?(.+?)/?\]\(|[$3](|g

[https://www.example.com/](https://www.example.com/)[example.com](https://www.example.com/)

Also from siralmat in the Apply Patterns examples.


Bold the repo name in GitHub links

Pasted GitHub links with fetched titles read like GitHub - owner/repo: description. This restyles them with the repo name in bold:

# Bold the repo name in GitHub links
s|\[(GitHub - ){0,1}([A-Za-z-\d)]+)\/([A-Za-z\d\-_.]+)(: [^\]]+){0,1}\]\(https:\/\/github.com\/([A-Za-z-\d)]+)\/([A-Za-z\d\-_.]+)\/?\)|[$2/**$3**](https://github.com/$2/$3)$4|g

[GitHub - owner/repo: My tool](https://github.com/owner/repo)[owner/**repo**](https://github.com/owner/repo): My tool

From claremacrae in the Apply Patterns examples.


HTML leftovers

Some sites leave HTML behind in the converted markdown. Run these in this order: line breaks first, then comments, then remaining tags, then entities.


Convert br tags to line breaks

# Convert br tags to line breaks
s/<br\s*\/?>/\n/gi

one<br/>twoone⏎two

From Polynomial on Stack Overflow.


Remove HTML comments

# Remove HTML comments
s/<!--[\s\S]*?-->//g

Intro<!-- TODO --> paragraphIntro paragraph

From Mike Samuel on Stack Overflow.


Remove leftover HTML tags

# Remove leftover HTML tags
s|</?[a-z][a-z0-9]*(\s[^>]*)?/?>||gi

Some <span class="x">highlighted</span> textSome highlighted text

It keeps prose like x < y and autolinks like <https://example.com> intact. A tamer form of nickf's answer on Stack Overflow.


Decode HTML entities

Escaped entities sometimes survive too. One snippet, six rules, and &amp; must stay last or it double-decodes:

# Decode HTML entities
s/&nbsp;/ /g
s/&lt;/</g
s/&gt;/>/g
s/&quot;/"/g
s/&#39;/'/g
s/&amp;/&/g

Fish &amp; Chips &lt;est. 1975&gt;Fish & Chips <est. 1975>

After lodash's unescape.


Lists and spacing


Collapse blank lines

Text copied from a chat often arrives with runs of blank lines. This folds every run into one:

# Collapse runs of blank lines into one
s/\n(?:[ \t]*\n){2,}/\n\n/g

one⏎⏎⏎⏎twoone⏎⏎two

Want no blank lines at all? Use s/\n(?:[ \t]*\n)+/\n/g instead. Keep in mind that Markdown joins lines without a blank line between them into one paragraph.


Remove spaces at line ends

# Remove spaces at line ends
s/[ \t]+$//gm

The end. ⏎Next lineThe end.⏎Next line

The m flag makes $ match the end of every line instead of the end of the text.


Fix spacing after list markers

Word and Pandoc exports pad list markers with extra spaces:

# Fix spacing after list markers
s/^(\s*([-*]|\d\.))\s{2,}/$1 /gm

- item one- item one

From siralmat in the Apply Patterns examples.


Use dashes for bullets

Prefer dashes over asterisks for bullets:

# Use dashes for bullets
s/^(\s*)\* /$1- /gm

* first point- first point

Adapted from keathmilligan's Paste Reformatter examples.


Collapse double spaces between words

Double spaces between words, without touching indentation:

# Collapse double spaces between words
s/(?<=\S) {2,}(?=\S)/ /g

the quick brown foxthe quick brown fox

Adapted from BalusC's answer on Stack Overflow.


Writing your own

Rules are JavaScript regular expressions, applied to the whole pasted text from top to bottom.

  • Flags: g replaces every match, i ignores case, m makes ^ and $ work per line.
  • The delimiter after s is your choice. s|http://|https://|g avoids escaping slashes.
  • In the replacement, $1 inserts the first captured group, \n a newline, \t a tab.
  • Lines starting with # or // are comments.
  • The first # comment names the snippet when you import it or paste it into the editor.

Test your rules in the Try it box in settings, or in the Better Paste playground on regex101. It opens with the citation pattern, a Perplexity sample, and the flavor set to JavaScript, which is the engine the plugin uses.

Have a snippet others could use? Open an issue and I will add it here.

Clone this wiki locally