Regex – Find everything except – Caret

I found this regex useful when parsing log files to find everything except the data I needed. I can select and delete everything I don’t need and I am left with the lines of data I can work with.

^(?!foo).+

This regex basically uses the caret (^) to find all lines that do not start with foo. To use it, just replace foo with whatever text starts the lines you need.

Combine that with Sublime Text’s multiple selection tool Command + Ctrl + G and you have a simple way to remove everything you need from a mixed bag log file.

Hinterlasse einen Kommentar