Things I can’t remember: More GREP goodness

When cleaning up mailing lists, I often need to remove the zip+4 info. It is usually at the end of a line so this grep works in BBEdit to find them.


-[0-9]{4}$

Look for a dash followed by the numbers 0-9 four times and then an end of line.

Working on a word list, we needed to find and delete all of the words with 1, 2, or 3 letters. So we use this code switching out the 1 for 2 and 3. Note the ^ and $. This means that we start at the beginning of the line look for the pattern and nothing else until the end of the line.


^[a-zA-Z]{1}$

We could use the same technique to find all of the words with more than 5 letters, but then we’d have to do a bunch of searches. Instead we used this.


[a-zA-Z]{5}[a-zA-Z]

Here we look for pattern of five letters and then look for one more. Not to belabor the point, but suppose together is in the word list. It has five letters, toget and one more h. It also happens to have some more letters after that, but we don’t particularly care. We just care that there are more than 5.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.