Notepad++ Change List in the format "Firstname Lastname" to "[email protected];"

194 views Asked by At

So I regularly get lists of names and need to be changing them into email addresses. They arrive like,

Firstname1 Lastname1

Firstname2 Lastname2 ...and so on.

How can I use Notepad++ to change them into this?

[email protected];

[email protected]; ...and so on?

I've never studied regular expressions but I suppose there must be a way of doing this fairly simply. I've searched on Google but nobody seems to have asked this precise question before. Also - it needs to retain the CRLF at the ends of the lines...

1

There are 1 answers

0
trincot On

Assuming your text file has no lines with 2 or more spaces, you could use this:

Press Ctrl+H to open the Find/Replace popup, and then:

          Find what: (.+) (note the space at the start!)
      Replace with: .\[email protected]

Search mode:

      ⦿ Regular expression ▢ . matches newline

Click Replace All

Explanation

  • : the space matches a literal space
  • .+: requires at least one more character after that space, and captures all remaining characters until the end of the same line (In practice this is the last name).
  • (): the parentheses make it possible to make reference to the captured group with \1

In the replace box, all characters are literal, except for \1 as explained above. Note that the first name is not captured, as nothing needs to be replaced there.