Skip to content

Instantly share code, notes, and snippets.

@sagirk
Last active May 22, 2018 11:35
Show Gist options
  • Save sagirk/9ae78b3bd8aebec5d27182b29aeed8a6 to your computer and use it in GitHub Desktop.
Save sagirk/9ae78b3bd8aebec5d27182b29aeed8a6 to your computer and use it in GitHub Desktop.
Regular expression to search for functions (regular and fat arrow) in JavaScript code
/**
* Match for patterns: `function (...) {...}` and `(...) => {...}`
* (`...` could be zero or more words, digits, spaces, underscores, commas)
*/
/function\s*\(([\w\d\s_,]*)\)\s*\{([^}]*)\}|\(([\w\d\s_,]*)\)\s*=>\s*\{([^}]*)\}/gi
/**
* Match for patterns: `function (...)` and `(...) =>`
* (`...` could be zero or more words, digits, spaces, underscores, commas)
*/
/function\s*\(([\w\d\s_,]*)\)|\(([\w\d\s_,]*)\)\s*=>/gi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment