Jacek
Jacek

Reputation: 12053

VisualStudio search text using regex to find method

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[)]

Upvotes: 2

Views: 177

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626754

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.

Upvotes: 2

Related Questions