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


#1

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


#2

Did you try this one?

function\("\w*"\)

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

https://regex101.com/


#4

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

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


#5

well it only replaces function with one argument when there are more nothin’ if you can help https://regex101.com/r/oN5bO9/1


#6

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


#7

I want another regex (the same link I updated it ) replace
case: .........return {};
with
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 }
#8

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 }.


#9

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


#10

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.


#11

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