Reputation: 12053
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
Reputation: 626754
You may use \w+
or [^,()]+
to match those unknown substrings:
\bGetById\(\w+,\s*transaction\s*\)
Details:
\b
- word boundaryGetById\(
- a literal GetById(
string\w+
- 1 or more letters, digits, or underscore
[^,()]+
- 1+ chars other than ,
, (
and )
,
- a comma\s*
- 0+ whitespacestransaction
- a literal word\s*
- 0+ whitespaces\)
- a )
symbol.Upvotes: 2