Skip to content

Instantly share code, notes, and snippets.

@aidant
Last active July 24, 2023 01:02
Show Gist options
  • Save aidant/ac497bf373f28e25c89901647f60eb64 to your computer and use it in GitHub Desktop.
Save aidant/ac497bf373f28e25c89901647f60eb64 to your computer and use it in GitHub Desktop.
Useful find and replace regex

Replace import with require()

Find

import ([A-Za-z_]+|{ ?([a-zA-Z_]+,? ?)+ ?}) from (\'[a-z-_0-9\.\/-]+\');?

Replace

const $1 = require($3)

Replace require() with import

Find

const ([A-Za-z_]+|\{ ?([a-zA-Z_]+,? ?)+ ?\}) = require\(('[a-z-_0-9\.\/-]+')\);?

Replace

import $1 from $3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment