14

In VS2010, what would be the regular expression for 'Find in Files' to search for all source files that contain two separate words regardless of line breaks?

For Example I want to find any source file that contains 'This' and 'That'.

I tried something like this but it did not work:

((This).* \n* .*(That))

Bud
  • 183
  • 1
  • 2
  • 7
  • 1
    Possible duplicate of http://stackoverflow.com/questions/520252/is-there-a-regular-expression-to-find-two-different-words-in-a-sentence – Jason Feb 24 '12 at 21:02
  • 2
    That response talks about using regex in code. I am wanting to use VS2010 to search my code. – Bud Feb 24 '12 at 21:54

2 Answers2

26

'this' followed by anything including newline followed by 'that',
or
'that' followed by anything including newline followed by 'this':

((this)(.*\n)*.*(that))|((that)(.*\n)*.*(this))
demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
  • That works if the words are on the same line. I'm trying to find the magic that will find the files were they are one or more lines apart. – Bud Feb 24 '12 at 22:32
  • Updated answer. Regex longer than about 10 chars makes me feel sick though, but it seemed to work for me. – demoncodemonkey Feb 24 '12 at 22:44
3

I find it easier to just do this, eg:

select|insert|update|delete

Note: VS's search needs to be set to use regular expressions. The order of the words does not matter.

So, we end up with something like this: enter image description here

EDIT: To find a list, just do "Entire Solution", and then "Find all". enter image description here

enter image description here

Fred
  • 2,402
  • 4
  • 31
  • 58
  • 2
    The question was how to list files containing all search terms. – Elaskanator Jun 08 '18 at 18:45
  • Then you just do a "Find all files" instead of "Current Document" - and you have your list in VS :) – Fred Jun 09 '18 at 05:57
  • 7
    You have still failed to answer the question. The vertical line character is disjunction (meaning matches term A or term B), but OP asked to match on files containing ALL search terms (meaning matches term A and term B). – Elaskanator Jun 12 '18 at 15:30