Skip to content

Instantly share code, notes, and snippets.

@Apollinaire
Created January 18, 2019 11:06
Show Gist options
  • Save Apollinaire/022ad0939fb9f9dc1f972565f1c7e3f1 to your computer and use it in GitHub Desktop.
Save Apollinaire/022ad0939fb9f9dc1f972565f1c7e3f1 to your computer and use it in GitHub Desktop.
Regex to find arrow functions with default value
const regEx = /\(.*(=+).*\) =>/;
// saved regex with examples: https://regex101.com/r/DcCtwT/1
// this will match the functions of this type:
const ArrowWithDefault = (argument = {whatever: 'abcdef'}) => {
return argument.whatever;
}
// NB: it won't match if the parenthesis are missing, or if the space before the arrow is missing
// the following will not match
const WontMatch = (argument = {whatever: 'abcdef'})=> {
return argument.whatever;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment