I often use the search feature in Sublime Text to search folders - some of these folders contain extremely long lines (1000's of chars long) due to minified code, base64 encoded data or certificates.
Search results often come back looking like the following (which is both annoying visually, as well as giving me accidental matches on shorter strings):
Is there a way I can omit lines greater than a certain length from my search results?
You can achieve what you are after (to a degree) using negative look ahead and negative look behind syntax.
Just suppose you didn't want to include any lines over 50 characters long where you are searching word MATCH, the following regex would work (?<!.{46})MATCH(?!.{46})
Scenarios (first 4 lines produce a match, the following 3 do not)
xxxxxxxxxxxxxMATCHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50
MATCHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx50
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMATCH
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMATCHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx95
MATCHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx51
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMATCH
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxMATCHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx96
In this example the longest line included in the returned result set will be of length 95 characters as there are 45 before and after the word MATCH. so not perfect but close, and for your purpose I'm sure it will do to exclude those super long lines of encoded data.
You can tune the length of the look behind and look ahead to get the result you are after.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With