Joshua's Docs - Regex Snippets
Light

Replace 2 spaces with tabs

  • Find: ^([\t]*)[ ]{2}
  • Replace: $1\t

Markdown RegEx Snippets

Increase Heading Indent Level

  • Find: ^#
  • Replace ##
  • Find: ([^!]{1})\[([^\[\]]+)\]\(([^)]+)\)
  • Replace: $1<a href="$3" rel="noopener" target="_blank">$2</a>

Find Lists that are missing empty line prefix

Empty lines before lists are required in many non-commonmark implementations of Markdown. This should find them (although it will also flag front-matter)

// https://regexr.com/5fqoh
const pattern = /^.+(?:\r\n|[\r\n]{1})[ \t]*(?:[-*]|\d\.)/gm;
const testStr = `
Paragraph text
 - List item A
 - List item B
 - List item C

Paragraph text
	- List item A
	- List item B
	- List item C
	
Paragraph text
 1. List item A
 2. List item B
 3. List item C
 
23 paragraph text
 - List item A
 - List item B
 
Paragraph text

 - List item A
 - List item B
`;

Remove front-matter block

  • Pattern: ---[\r\n]+(?:.|[\r\n])*---[\r\n]*

JS / TS Source Code

Match Imports

Matches top of file imports (RegExr Demo):

/^import\s+.+from.+;?$|import\s+\{[^\}]+\}.+from.+;?$|^import\s["'].+["'].*;?$/gim
Markdown Source Last Updated:
Sun Feb 27 2022 23:34:54 GMT+0000 (Coordinated Universal Time)
Markdown Source Created:
Tue Dec 31 2019 00:15:59 GMT+0000 (Coordinated Universal Time)
© 2024 Joshua Tzucker, Built with Gatsby
Feedback