-
-
Notifications
You must be signed in to change notification settings - Fork 0
Snippets
41 snippets. Last updated: 2026-08-21
Better Paste has two kinds of snippets. Text snippets run on everything you paste. Link snippets rewrite the fetched page title when you paste a web address. Each snippet is a list of find and replace rules, one per line, and the patterns are JavaScript regular expressions. Put the name in a # comment at the top:
# Name of the snippet
s/find/replace/flags
s/find/replace/flags
Copy any block below, add a snippet with the (+) button, and paste into the rules field. Each section says where in settings its snippets live. Want to try a rule first? Open the Better Paste playground on regex101. In the examples, ⏎ marks a line break.
Text snippets run on the whole pasted text, after the built-in rules, on every paste. Add them under Settings → Better Paste → Custom processing.
Perplexity cites as it writes, and the numbered markers come along when you copy. 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.
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] end → Qubits. end
text⏎[^1_3]: https://ex.com⏎tail → text⏎tail
From ckep1's Perplexity chat exporter.
Answers that used web search sometimes leak internal reference tags into the copied text. Some are visible, like :contentReference[oaicite:3]{index=3}, and some are citation runs wrapped in invisible private-use characters:
# Remove ChatGPT reference tags
# Remove visible tags like :contentReference[oaicite:3]{index=3}
s/:{0,2}contentReference\[oaicite:\d+\]\{index=\d+\}//g
# Remove invisible citation runs wrapped in U+E200 and U+E201
s/[ \t]*\u{E200}[^\u{E201}]*\u{E201}//gu
Paris hosted them.:contentReference[oaicite:3]{index=3} → Paris hosted them.
The invisible runs read like citeturn0search3 when something makes them visible. The first pattern comes from fwerner13's normalize-chatgpt plugin; the invisible markers are reported in r/ChatGPT.
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.
Academic text and markdown exports carry footnote markers like [^12]:
# Remove footnote markers like [^12]
s/\[\^\d{1,3}\]//g
disputed.[^12] Later → disputed. Later
From gino_m on the Obsidian forum.
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.
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 $. Snippets see the whole paste, code blocks included, so a literal \( inside code converts too. Check the result the first time.
LLMs sprinkle --- between sections. This deletes those lines:
# Remove horizontal rule lines
s/^[ \t]*---[ \t]*\n//gm
end.⏎---⏎## Next → end.⏎## 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".
This strips decorative emoji, the 🚀 and 🎯 kind that AI answers put in headings:
# Remove emoji
# At the start of a line, with the space after it
s/^[\p{Extended_Pictographic}\u{1F1E6}-\u{1F1FF}\u{1F3FB}-\u{1F3FF}\u{20E3}\u{FE0F}\u{200D}]+[ \t]*//gmu
# Everywhere else, with the space before it
s/[ \t]*[\p{Extended_Pictographic}\u{1F1E6}-\u{1F1FF}\u{1F3FB}-\u{1F3FF}\u{20E3}\u{FE0F}\u{200D}]+//gu
## 🚀 Getting started → ## Getting started
Done 🚀. → Done.
Symbols with a text meaning, like ⌘ and →, are kept. Adapted from GoSlowPoke168's Clean AI Paste.
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) now → See the docs now
Adapted from stiang's remove-markdown.
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
Also from remove-markdown.
Web copies often contain links with no text at all, like [](#anchor):
# Remove empty links
s/(?<!!)\[\]\([^)]*\)//g
Overview[](#_anchor) of → Overview of
Adapted from ratacat's slurp-ai scraper.
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.
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.
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. This one runs on links inside copied text. For a bare pasted address, Clean GitHub titles does the same job on the fetched title.
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
s/<br\s*\/?>/\n/gi
one<br/>two → one⏎two
From Polynomial on Stack Overflow.
# Remove HTML comments
s/<!--[\s\S]*?-->//g
Intro<!-- TODO --> paragraph → Intro paragraph
From Mike Samuel on Stack Overflow.
# Remove leftover HTML tags
s|</?[a-z][a-z0-9]*(\s[^>]*)?/?>||gi
Some <span class="x">highlighted</span> text → Some 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.
Escaped entities sometimes survive too. One snippet, six rules, and & must stay last or it double-decodes:
# Decode HTML entities
s/ / /g
s/</</g
s/>/>/g
s/"/"/g
s/'/'/g
s/&/&/g
Fish & Chips <est. 1975> → Fish & Chips <est. 1975>
After lodash's unescape.
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⏎⏎⏎⏎two → one⏎⏎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
s/[ \t]+$//gm
The end. ⏎Next line → The end.⏎Next line
The m flag makes $ match the end of every line instead of the end of the text.
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.
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.
Double spaces between words, without touching indentation:
# Collapse double spaces between words
s/(?<=\S) {2,}(?=\S)/ /g
the quick brown fox → the quick brown fox
Adapted from BalusC's answer on Stack Overflow.
Link snippets run when you paste a web address by itself and Fetch titles for pasted links is on. The plugin fetches the page title, builds a Markdown link, and runs your enabled link snippets on that one line:
[GitHub - noisetorch/NoiseTorch: Real-time microphone noise suppression on Linux. · GitHub](https://github.com/noisetorch/NoiseTorch)
A rule sees the whole line, so it can target one site by matching the address part. But it can only change the title: a result that touches the address is discarded, and the plain titled link is used instead. So a broken rule can never break your link. Add link snippets under Settings → Better Paste → Links → Link snippets.
GitHub writes its name twice, once as a prefix and once after a middle dot. This keeps just owner/repo: description:
# Clean GitHub titles
# Repo pages: remove the GitHub prefix and suffix
s#^\[GitHub - ([^\]]+) · GitHub\](\(https://github\.com/\S+\))$#[$1]$2#
# Issues and pull requests: remove the suffix
s#^\[([^\]]+) · GitHub\](\(https://github\.com/\S+\))$#[$1]$2#
Before: GitHub - noisetorch/NoiseTorch: Real-time microphone noise suppression on Linux. · GitHub
After: noisetorch/NoiseTorch: Real-time microphone noise suppression on Linux.
The most wished-for title cleanup in Auto Link Title's issue tracker.
An X post title contains the entire tweet. This cuts the label at a word boundary around 72 characters and keeps the / X marker, so you still see where the link goes:
# Shorten X post titles
s#^\[(?=[^\]]{90})(.{40,72})\s[^\]]{5,} / X\](\(https://(?:x|twitter)\.com/\S+\))$#[$1 … / X]$2#
After: Obsidian on X: "Obsidian is now free for work. Starting today, the … / X
Titles under 90 characters stay whole. Prefer just the author? Use s#^\[(.+?) (\S+) X: .+ / X\](\(https://(?:x|twitter)\.com/\S+\))$#[$1 $2 X]$3# instead, which turns the same paste into Obsidian on X. The word between the name and X is localized ("on", "på", "auf"), so both rules accept any word there.
# Remove the YouTube suffix
s#^\[(.+) - YouTube\](\(https://(?:www\.|m\.)?(?:youtube\.com|youtu\.be)/\S+\))$#[$1]$2#
Rick Astley - Never Gonna Give You Up (Official Video) - YouTube → Rick Astley - Never Gonna Give You Up (Official Video)
The greedy (.+) means only the final - YouTube goes, so dashes inside video titles survive.
Reddit appends the subreddit to the post title:
# Clean Reddit titles
s#^\[(.+) : r/[^\s\]]+\](\(https://(?:www\.|old\.)?reddit\.com/\S+\))$#[$1]$2#
Obsidian sync between PC and iOS : r/ObsidianMD → Obsidian sync between PC and iOS
Rather keep the subreddit in front? Use s#^\[(.+) : (r/[^\s\]]+)\](\(https://(?:www\.|old\.)?reddit\.com/\S+\))$#[$2: $1]$3# for r/ObsidianMD: Obsidian sync between PC and iOS.
Question titles carry the main tag in front and the site name at the end:
# Clean Stack Overflow titles
# Remove the site suffix
s~^\[(.+) - Stack Overflow\](\(https://stackoverflow\.com/\S+\))$~[$1]$2~
# Remove the leading tag
s~^\[[a-z0-9.#+-]{1,35} - (.+)\](\(https://stackoverflow\.com/questions/\S+\))$~[$1]$2~
java - Why is processing a sorted array faster than an unsorted array? - Stack Overflow → Why is processing a sorted array faster than an unsorted array?
The ~ delimiter keeps the # in the tag pattern (think c#) out of the way. Asked for in copy-as-markdown #125.
Every language edition appends its own name after a dash, and some add a tagline:
# Remove the Wikipedia suffix
s#^\[(.+) [-–—] [^\]]+\](\(https://[a-z-]+\.(?:m\.)?wikipedia\.org/\S+\))$#[$1]$2#
Obsidian (software) - Wikipedia → Obsidian (software)
Obsidiana - Wikipedia, la enciclopedia libre → Obsidiana
The character class covers the hyphen, en dash and em dash the different editions use.
Products get an Amazon.com: prefix and a category suffix. Books get the author, the ISBN and the store appended:
# Clean Amazon titles
# Products: remove the prefix and category
s#^\[Amazon\.com: (.+?)(?: : [^:\]]+)?\](\(https://www\.amazon\.com/\S+\))$#[$1]$2#
# Books: keep only the title
s#^\[(.+): [^:\]]+: [\dX]{10,13}: Amazon\.com: Books\](\(https://www\.amazon\.com/\S+\))$#[$1]$2#
After: Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones
Shopping on another marketplace? Widen www\.amazon\.com to www\.amazon\.\S+ and Amazon\.com to Amazon\.[a-z.]+. Amazon titles stay long even after cleaning, so pair this with Truncate long titles.
# Remove the npm suffix
s#^\[(.+) - npm\](\(https://www\.npmjs\.com/\S+\))$#[$1]$2#
# Remove the Hacker News suffix
s#^\[(.+) \| Hacker News\](\(https://news\.ycombinator\.com/\S+\))$#[$1]$2#
Ask HN: What plugin cleans up pasted links? | Hacker News → Ask HN: What plugin cleans up pasted links?
Medium appends the author and often the publication:
# Clean Medium titles
s#^\[(.+) \| by [^\]]+\](\(https://(?:[\w-]+\.)?medium\.com/\S+\))$#[$1]$2#
s#^\[(.+) \| Medium\](\(https://(?:[\w-]+\.)?medium\.com/\S+\))$#[$1]$2#
Medium Titles, Subtitles, and Kickers | by Casey Botticello | Blogging Guide | Medium → Medium Titles, Subtitles, and Kickers
# Remove the MDN suffix
s#^\[(.+) \| MDN\](\(https://developer\.mozilla\.org/\S+\))$#[$1]$2#
Array.prototype.map() - JavaScript | MDN → Array.prototype.map() - JavaScript
The technology name stays, which is useful context.
Post titles end in a comment count or the site name:
# Clean LinkedIn titles
s#^\[(.+) \| (?:[\d,.]+ comments|LinkedIn)\](\(https://(?:www\.)?linkedin\.com/\S+\))$#[$1]$2#
Sam Browne on LinkedIn: The LinkedIn Comment Guide | 405 comments → Sam Browne on LinkedIn: The LinkedIn Comment Guide
Paper titles start with the bracketed id:
# Clean arXiv titles
s#^\[\[\d{4}\.\d{4,5}(?:v\d+)?\] (.+)\](\(https://arxiv\.org/\S+\))$#[$1]$2#
[1706.03762] Attention Is All You Need → Attention Is All You Need
Substack publications live on their own domains, so this one matches the byline instead of the address:
# Remove Substack bylines
s#^\[(.+) - by [A-Z][^\]]{1,40}\](\(https?://\S+\))$#[$1]$2#
Why Substack is at a crossroads - by Casey Newton → Why Substack is at a crossroads
Any title ending in - by Someone matches, whatever the site, so check the result now and then.
These run on links from any site. Snippets run in list order, so drag them below your site fixes.
News sites and blogs end their titles with | Site Name or — Site Name:
# Strip site name suffixes
s#^\[(.{10,}) \| [A-Z][^|\]]{1,29}\](\(https?://\S+\))$#[$1]$2#
s#^\[(.{10,}) [–—] [A-Z][^–—\]]{1,29}\](\(https?://\S+\))$#[$1]$2#
Why Obsidian will outlast the AI note wave | The Verge → Why Obsidian will outlast the AI note wave
The spaced pipe, en dash and em dash almost never appear inside a real title, so these two are safe to leave on.
The plain hyphen version needs more care, because real titles contain hyphens too:
# Strip hyphen site suffixes
s#^\[(.{10,}) - (?:(?:The )?[A-Z][\w.&'’]*(?: [A-Z][\w.&'’]*){0,3})\](\(https?://\S+\))$#[$1]$2#
Better Paste cleans everything - The Verge → Better Paste cleans everything
It only strips a short capitalized tail, so My trip to Japan - part 2 keeps its ending. A title that happens to end in a name, like Yesterday - The Beatles, still loses it. Switch this one on with that in mind.
# Truncate long titles
s#^\[(?=[^\]]{96})(.{60,80})\s[^\]]{5,}\](\(https?://\S+\))$#[$1 …]$2#
After: Amazon.com: Apple AirPods Pro 2 Wireless Earbuds, Active Noise Cancellation, …
Labels up to 95 characters stay whole. Longer ones are cut at a word boundary around 80 characters, with an ellipsis. Requested often enough that Auto Link Title made it a setting, see #75.
Rules are JavaScript regular expressions, applied 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://|gavoids 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.
Text snippet rules see the whole pasted text. Link snippet rules see one line, [Title](url), before any Markdown escaping, so patterns match raw | and [ in titles. Three more things about link rules:
- The address is read-only. A result that does not keep the exact pasted address, or that empties the title, is discarded and the plain titled link is used.
- Match the address to scope a rule to one site: end the pattern with something like
\](\(https://github\.com/\S+\))$and put$2back in the replacement. - Titles and addresses are full of
/and|, so the link rules above use#or~as the delimiter.
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.