-1

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?

Firstname1.Lastname1@ourdomain.com;

Firstname2.Lastname2@ourdomain.com; ...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...

  • I don't know Notepad++, but for matching exactly 2 words per line, a `(\w+) (\w+)` can do the job, see https://regex101.com/r/DTEK8z/1 - however personally I'd just replace every single space with a dot in that file as a separate step (no regex involved), then it becomes a match-everything `(.*)`, and it won't matter any more how many names a person may have, https://regex101.com/r/50fDk6/2 – tevemadar Mar 08 '23 at 11:46

1 Answers1

0

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: .\1@ourdomain.com

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.

trincot
  • 317,000
  • 35
  • 244
  • 286