2

I have string1 and string2 and a bunch of text files in a folder. The files may contain any number of occurrences of string1 or string2.

Is there a way to use Sublime Text's "Find in Files..." utility to find all files containing at least one occurrence of each?

Looking into the subject I've been able to find a way to search for the or of multiple strings (i.e. matching either matches the entire file), but what I'm trying to do is an and. On the other hand using non-consuming regular expressions as suggested in this answer simply doesn't seem to work in Sublime Text 2 (always yields zero matches).

Community
  • 1
  • 1
Sanuuu
  • 243
  • 1
  • 10
  • Use alternation: `string1|string2` – Wiktor Stribiżew Feb 29 '16 at 13:03
  • @WiktorStribiżew this is an example of something I'm not looking for. I even put it right there in the question (first link). – Sanuuu Feb 29 '16 at 13:08
  • 3
    Then you should remove the *at least one occurrence of each*, it is misleading. You need `(?s)string1.*string2|string2.*string1` or `(?s)^(?=.*string1)(?=.*string2)`. – Wiktor Stribiżew Feb 29 '16 at 13:11
  • 1
    I thought emphasizing 'each' in bold separately from the 'at least one' made it clear. I'll try to think of a way to re-phrease. – Sanuuu Feb 29 '16 at 14:22

1 Answers1

5

This RegEx pattern will enable you to find files which contain each of your string queries: (string1[\s\S]*string2)|(string2[\s\S]*string1)

[\s\S]* is used to match any character ( including line breaks ) as many times as necessary until the following set of characters is found.

Multiple Query RegEx Pattern

Enteleform
  • 3,753
  • 1
  • 15
  • 30
  • `[\s\S]*?` will further improve search efficiency by using the first instance of the following set of characters ( as opposed to the final instance, if `?` is omitted ). – Enteleform Mar 07 '16 at 11:06