[Solved] Regex to replace function foo(a,b) to function foo(b,a) [closed]


Search for (with regex setting turned on)

BeanUtils\.copyProperties\s*\(\s*([\w\_]+)\s*\,\s*([\w\_]+)\s*\)\s*\;

And replace with:

BeanUtils.copyProperties($2, $1);

First escape all literal characters with backslash \

Wherever a space can be found when writing code, match it with 0 or more spaces. That by using \s* Could use [ ]* but \s might be sufficient in this case.

Then add captures for the source and destination by adding them in brackets. Or use [\w\_]+ to match other variable names. With a + to mean at least 1 char. NB: if your variable have any other non-alphanumeric chars, add them to the [...] list.

Finally in the replace, switch the captures.

6

solved Regex to replace function foo(a,b) to function foo(b,a) [closed]