Search code examples
grepsublimetext3

SUBLIME & GREP: Conduct a GREP search, but exclude lines that are in all in capitals


I am using a GREP search in the find function of Sublime Text 3. I want to find all lines that are more than 12 characters, excluding spaces. As discussed in this Stack Overflow thread, the way to do this is with the following command:

^\h*(?:\S\h*){13,}$

But I also want the GREP search to exclude all lines that are written in all caps, when it is conducting the above search.

Example:

FAVORITE FOODS OF AMERICA 
Mac and Cheese
Peanut Butter and Jelly Sandwich
  • In the above example, Mac and Cheese would not be found, because it's exactly 12 characters excluding spaces.
  • FAVORITE FOODS OF AMERICA would also not be found because although it's more than 12 characters, it is a line that is written in all caps.
  • Only Peanut Butter and Jelly Sandwich would be found, because it's more than 12 characters and although it has capital letters, the line is not written in all caps.

How would I do this? Googling around I can find Grep commands that exclude lines that contain at least one capital letter, but not lines that are only in all caps.

Note: I am using the Grep option in Sublime's Find function.


Solution

  • You could use a negative lookahead asserting what is on the right is not only uppercase chars with possible horizontal whitespace chars.

    ^(?![A-Z\h]+$)\h*(?:\S\h*){13,}$
    

    Regex demo