Skip to content

Regex and rewrite cheat sheet

A regex rule tests one pattern against the whole link, including https://. The pattern can match anywhere in the link. Case does not matter. A pattern that will not compile never matches.

PieceMeaningExample
\.A literal dot.zoom\.us
.Any one character.v. matches v1
[abc]One character from the set.[xy]\.com
[a-z0-9]One character from the range.[a-z0-9]+
[^/]One character that is not in the set.[^/]+ matches up to the next slash
*The piece before it, zero or more times..*
+The piece before it, one or more times.[0-9]+
?The piece before it, zero or one time.(www\.)?
{n} and {n,m}The piece before it, n times, or n to m times.[0-9]{4}
^ and $The start and the end of the link.^https://
a|bEither a or b.twitter\.com|x\.com
( )A group. Also captures the text it matched for a rewrite.(twitter\.com|x\.com)

A rewrite uses the Replace with field. Its hint text is $1, $2....

TemplateInserts
$1 through $9The text captured by the first through ninth group.
$0The whole matched text.

Only the matched part of the link changes. Everything else stays. If the result is the same as the original link, no rewrite happens. The result must still be a valid link.

These are the patterns from three presets under URL Rewrites in Browse Presets.

PresetPatternReplacementBeforeAfter
Twitter/X → xcancel://(www\.)?(twitter\.com|x\.com)://xcancel.comhttps://twitter.com/user/status/123https://xcancel.com/user/status/123
Reddit → Old Reddit://(www\.)?reddit\.com://old.reddit.comhttps://reddit.com/r/programminghttps://old.reddit.com/r/programming
YouTube → Invidious://(www\.)?(youtube\.com|youtu\.be)://yewtu.behttps://youtube.com/watch?v=abchttps://yewtu.be/watch?v=abc