3

I have a very large codebase in which in want to find all linq statements that not contain the where cause.

So, lets say I have a linq statement like this:

from t in dc.tablename where t.somefield="somevalue" select t

This statement should NOT be included into the search result, but, if the statement looks like this:

from t in dc.tablename select t

this should be included into the search result.

So far I've only managed to create a regex for matching linq statements that contain the WHERE:

from(.|\n){1,}(where)(.|\n){1,}select

But when I try this:

from(.|\n){1,}^(where)(.|\n){1,}select

it does not work.

timss
  • 9,982
  • 4
  • 34
  • 56
user1307533
  • 169
  • 2
  • 3
  • 10

1 Answers1

1

You could maybe try out this regex:

from(?:(?!where|select)[\s\S])+select

(?:(?!where|select)[\s\S])+ will match any characters (including newlines) except where and select so that you don't have to worry about greediness either.

Jerry
  • 70,495
  • 13
  • 100
  • 144
  • thanks, it seems to be working, although it gives fake results also, but at least I've found the LINQs. – user1307533 Mar 19 '14 at 13:37
  • @user1307533 Okay. Could you perhaps give an example of fake results? If it helps you getting only the relevant lines :) – Jerry Mar 19 '14 at 13:38
  • For example: /// To modify move field declaration from designer file to code-behind file. This is also a result, but I don't understand why.. maybe the Visual Studio's regex search is f*cked up somehow :) – user1307533 Mar 19 '14 at 13:45
  • 1
    @user1307533 Nah, it's matching all right. Do all the LINQs you need begin on a new line with `select`? If so, you could simply add `^[ \t]*` at the beginning of the regex. This will make sure to match only lines that begin with `from` (with optional indentation). – Jerry Mar 19 '14 at 13:48