Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex to find missing ConfigureAwait

I have a specific pattern that I want to search for in Visual Studio.

Basically, I want to search for lines that contains await, but are missing ConfigureAwait at the end of the statement.

I have some patterns that works in regex-testers such as regex101.com, but I can't get these patterns to work in Visual Studio search. For example, the pattern (?s)^(.)*(await)((?!ConfigureAwait).)*(.)?(;).

What I am doing wrong?

Edit - I want to find lines in my project such as

await DoSomeCoolThings(x, y); (i.e. missing the ConfigureAwait(...).)

but I don't want to get a match for lines such as:

await DoSomeCoolThings(x, y).ConfigureAwait(false);

like image 692
Superhubert Avatar asked Apr 19 '16 06:04

Superhubert


1 Answers

If the order of await and ConfigureAwait does not matter, then you can use

(?=.*\bawait\b)(?!.*\bConfigureAwait\b)

otherwise, if you consider that ConfigureAwait should come after await, you can use

(?=.*\bawait\b(?!.*\bConfigureAwait\b))

Efficient Solution

(?=\bawait\b(?!.*\bConfigureAwait\b))
like image 193
rock321987 Avatar answered Nov 15 '22 05:11

rock321987