Created
January 18, 2019 11:06
-
-
Save Apollinaire/022ad0939fb9f9dc1f972565f1c7e3f1 to your computer and use it in GitHub Desktop.
Regex to find arrow functions with default value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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