Things I Can’t Remember – REGEX

When using BBEdit I often want to see just the first part of a line. This REGEX expression has two parts. The first part looks for the first 75 characters and the second part looks for all the rest. Then I just replace the found string with the first part.

Search String:       ^(.{75})(.*)
Replacement String:   \1

The ^ says to start at the beginning of the line ($ is for the end). Then there are two patterns to look for. Each pattern is enclosed in parentheses. The first pattern looks for any single character (the dot). The number in between the braces {} says to look for the previous pattern 75 times. The second pattern looks for any single character repeated any number of times.

The replacement string is just the first pattern i.e. the first 75 characters of each line.

Leave a Reply

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