Regex to replace: "function(args)" with "(args) =>" - callback with arrow function


function("parameters") with ("parameters") => what’s the regex for it? You know to replace
function() with () =>
classic callback with arrow fucntion
I tried search function\((w+)\) and replace
($1) =>
but didn’t work


Did you try this one?


A useful website I use to get a visual representation of my regex results is this one, hope you can fix your regex.


You can try this: function\s*\(([^\)]+)\)

I basically takes everything that is not a parenthesis inside parentheses.


well it only replaces function with one argument when there are more nothin’ if you can help


my bad it was working but I forget /g in the regerx101


I want another regex (the same link I updated it ) replace
case: .........return {};
case: { .........return {}; }
you know Air bnb eslint :smiley: so there’s no chance of anything outta scope…

Replace regex case: ..."code"...return with case: { .... return }

The simplest way to do it is to divide it into steps. First search for (case\:) and replace with $1 {, then search for (return \{\}\;) and replace with $1 }.


but there can be others return not only those in case statemements, but I only want to target returns which are after cases


I think that in that case any find-and-replace solutions is doomed to failure. I would use find-and-replace to find where the case: are but probably make the change by hand.


or not ok so 1st put “{” after “case”: and then put “}” before andother “case” or “default”