Skip to content

Instantly share code, notes, and snippets.

@tscpp
Last active November 29, 2020 17:45
Show Gist options
  • Save tscpp/5390f835075bbb5907055cd153797ac3 to your computer and use it in GitHub Desktop.
Save tscpp/5390f835075bbb5907055cd153797ac3 to your computer and use it in GitHub Desktop.
Regex that can be used to replace require statements with ES6 import statements
Find: (^|\n)\s*(?:let|const|var)\s+(.+?)\s*=\s*require\s*\(\s*(?:'|")(.+?)(?:'|")\s*\)\s*(;(?:$|\n)|(?:$|\n))
Replace: $1import * as $2 from '$3'$4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment