2

How should regex looks in Visual Studio search text (Ctrl+Shift+f). I want to find all GetById method invocations where first argument has random name, but second has fixed name : 'transaction'

My examples

Sth1.Instance.GetById(formInstanceSessionId, transaction);
Sth2.Instance.GetById(userId, transaction);
Sth3.Instance.GetById(invoiceId, transaction);

I have tried the following regex, but it's not working:

GetById[(]*[,]\stransaction[)]

1 Answer 1

2

You may use \w+ or [^,()]+ to match those unknown substrings:

\bGetById\(\w+,\s*transaction\s*\)

enter image description here

Details:

  • \b - word boundary
  • GetById\( - a literal GetById( string
  • \w+ - 1 or more letters, digits, or underscore
    OR
  • [^,()]+ - 1+ chars other than ,, ( and )
  • , - a comma
  • \s* - 0+ whitespaces
  • transaction - a literal word
  • \s* - 0+ whitespaces
  • \) - a ) symbol.
Sign up to request clarification or add additional context in comments.

Comments

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.