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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s