1

In context of this question I want to do the following changes:

Find:

funcA(param0,param1,param2,param3);

Replace:

if(isTrue)
    funcB(param0,funcC(param1,param2,param3));

funcA can have any number of parameters besides param0.How can it be done?For simplicity ignore the base case i.e when param pass to funcA is only param0.

funcA is:

public void funcA(String param0,Object... params)

funcC is:

public void funcB(Object... params).

EDIT:

The parameters(param1,param2..) are just string containing alphabets.

Community
  • 1
  • 1
Atul
  • 33
  • 6

1 Answers1

1

Search regex:

^ *funcA *\(([^,\s;)]*) *(?:, *([^)\;]+))?

Replacement Pattern:

if(isTrue) funcB($1, funcC($2)

RegEx Demo

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Hi,this looks good.But can you make the regex first find funcA.Here it assumes that the given line is calling funcA.I have to do the replacement in my code – Atul Sep 24 '14 at 07:05
  • Thanks.It handle the base case also. – Atul Sep 24 '14 at 07:13
  • This isn't working for the situation below. funcA(param0); funcA(param0,param1,param2,param3);http://regex101.com/r/tO8qG1/3 – Atul Sep 24 '14 at 07:25
  • But you wrote: `For simplicity ignore the base case` What do you want `funcA(param0);` to be replaced by? – anubhava Sep 24 '14 at 07:27
  • Though this is what I asked for it will be great if you can provide regex for the base class also. http://regex101.com/r/tO8qG1/6 Here the 4th line should get converted to if(isTrue) funcB(param0,funcC()) – Atul Sep 24 '14 at 07:54