Regex Snippets: Expand Patterns, Not Just Words
Use regular expressions to match patterns and transform text with capture groups. Reformat phone numbers, wrap URLs, and more.
Normal snippets match exact text. Regex snippets match patterns. Type a phone number in one format, get it back in another. Type a raw URL, get a Markdown link. Type a date one way, reformat it another.
Setting Up a Regex Snippet
- Create a new snippet (Cmd+N)
- Switch Match Type from Exact to Regex
- Enter a regular expression pattern in the Pattern field
- Use
$1,$2, etc. in the content to reference captured groups
The editor validates your pattern in real time — you’ll see a green checkmark if it’s valid, or a red error message explaining what’s wrong. It also tells you how many capture groups your pattern contains.
Capture Groups
Parentheses in your pattern create capture groups. Each group gets a number:
$0— The entire matched text$1— First group$2— Second group- And so on…
Example: Reformat Phone Numbers
Pattern: tel:(\d{3})-(\d{3})-(\d{4})
Content: ($1) $2-$3
You type: tel:555-867-5309
You get: (555) 867-5309
The pattern matches tel: followed by three groups of digits. The content rearranges them into a different format.
Example: Markdown Link from URL
Pattern: mdlink:(https?://\S+)
Content: [$1]($1)
You type: mdlink:https://example.com
You get: [https://example.com](https://example.com)
Example: HTML Tag Wrapper
Pattern: wrap:(\w+):(.+)
Content: <$1>$2</$1>
You type: wrap:strong:important text
You get: <strong>important text</strong>
Two capture groups: the tag name and the content.
Practical Recipes
Quick Email Addresses
Pattern: @(\w+)
Content: [email protected]
You type: @aaron
You get: [email protected]
Date Reformatting
Pattern: date:(\d{1,2})/(\d{1,2})/(\d{4})
Content: $3-$2-$1
You type: date:15/01/2026
You get: 2026-01-15
Converts DD/MM/YYYY to ISO format.
CSS Color Shorthand
Pattern: rgb:(\d{1,3}),(\d{1,3}),(\d{1,3})
Content: rgb($1, $2, $3)
You type: rgb:232,93,4
You get: rgb(232, 93, 4)
Jira-Style Ticket Links
Pattern: (PROJ-\d+)
Content: [$0](https://jira.company.com/browse/$0)
You type: PROJ-1234
You get: [PROJ-1234](https://jira.company.com/browse/PROJ-1234)
Since $0 is the full match, you don’t even need explicit groups for simple patterns.
Timestamp from Shorthand
Pattern: t:(\d{1,2}):(\d{2})(a|p)
Content: $1:$2 $3m
You type: t:2:30p
You get: 2:30 pm
Tips for Writing Patterns
Start simple. Get a basic pattern working before adding complexity.
Use \d for digits, \w for word characters. These are safer than . which matches anything.
Escape special characters. If you need to match a literal . or (, prefix with \: \. or \(.
Test in the editor. The validation indicator tells you immediately if your pattern is valid and shows the capture group count.
Use non-capturing groups when needed. (?:...) groups without capturing, so it won’t shift your $1, $2 numbering.
Trigger Mode Matters
Regex snippets respect the same trigger modes as exact snippets:
- After Delimiter — The pattern must be followed by a space, punctuation, etc.
- Immediate — Matches and expands as soon as the pattern completes. Be careful with broad patterns — they might match more than you expect.
- Manual Only — Only expands via Quick Search or hotkey.
For regex snippets, After Delimiter is especially important. It prevents partial matches from firing while you’re still typing.
Combining with Macros
Regex content supports all standard macros. You can mix capture groups with dynamic values:
Pattern: log:(\w+):(.+)
Content: [{{date:yyyy-MM-dd}} {{time:HH:mm:ss}}] [$1] $2
You type: log:ERROR:Connection timed out
You get: [2026-01-15 14:30:45] [ERROR] Connection timed out
The pattern captures the level and message; the macros add the timestamp.
Regex snippets are the most powerful feature in TypeSnap. They turn typing into transformation — not just expansion, but reformatting on the fly.
Stop typing the same things over and over
TypeSnap expands your snippets instantly. One-time purchase, no subscription.