Skip to content

Instantly share code, notes, and snippets.

@robballou
Last active July 3, 2019 19:57
Show Gist options
  • Save robballou/dd72b6e51a6ebcc4e601a1e3e8c1fe0c to your computer and use it in GitHub Desktop.
Save robballou/dd72b6e51a6ebcc4e601a1e3e8c1fe0c to your computer and use it in GitHub Desktop.
JavaScript regex for find/replace
// Match function declarations for converting to function expressions
const regex = /^(export\s?)?(async\s?)?function ([^(]+)(\([^)]*\))(\s*:[^{]+)? {/
// replace: $1const $3 = $2$4$5 => {
// class methods... caution! this also replaces if statements
const regex2 = /([^(]+)\((.+)\) {/
// replace $1 = ($2) => {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment