0

I want to find an (overloaded) method X where the argument in position Y has the value Z.

Example:

AddMailToQueue("a", "b", "c", 2);
AddMailToQueue("a", "b", "c", 2, "d");
  • X: AddMailToQueue
  • Y: 4
  • Z: 2

The method name X may or may not be prefixed (eg this.AddMailToQueue).

I came up with the following: .*AddMailToQueue\(.+2.*\); but this regex does not take into account the position of the argument and will also return matches where Z = 20, 21, etc.

My reasoning is that the comma separating the arguments can probably be used to pinpoint argument Y.

1 Answer 1

1

Probably you want a .NET solution, but here is a regex that works in Java, then maybe you can convert it.

AddMailToQueue\s*\(([^,]+,){3}\s*2\s*[,)]

Things get easier if you start counting your parameters from zero. You would put the parameter's index Y where you see 3 and the paramater's value Z where you see 2.

See it working

Sign up to request clarification or add additional context in comments.

1 Comment

It works perfectly, no changes required! Also, removing the initial .* (just before the method name) made the search much faster!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.