howto://USE a REGEX to match everything up to the @


I use PSPAD as my default text editor. It’s been my favourite such application for years because it can do so much. Recently I was handed a CSV that contained email addresses for 25,000 users. I needed to pull out just the SMTP suffixes for some manipulation. PSPAD can do global search and replace with a REGEX and it seemed like just what I needed. The only challenge was to figure out what pattern matches everything in an email address up to and including the @ sign. Here’s the pattern I used.


That says to start at the beginning of the line, match any number of alphanumeric characters up to, and including the @. Easy.

2018-01-29 edit-since I am copying from and am too lazy to try to recreate all the great comments, I am adding this one from my former boss, Jim Palic of ONLC, which is an even easier way to do this.

Another easy way to do that would be to use the negation operator inside the square brackets. e.g. ^([^@]+)@ Meaning match everything that is not an @.

Leave a Reply

Your email address will not be published. Required fields are marked *

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