turning full names into email addresses

A swapping-ground for Regular Expression syntax

turning full names into email addresses

Postby msg » Wed Oct 12, 2016 3:34 pm

Hi everyone,

I've a a load of photographs of people that I want to associate with their email addresses.

The file names are in the format [Firstname] [Lastname].jpg
and their email address is in the format: [Firstinitial][Lastname]@domain.co.uk

So far, I've got the following regex that turns their first name into a first initial, removes the space, and adds their lastname:

Match: ^([A-Z])([a-z]*) ([A-Z][a-z]*)
Replace: \1\3

and combine this with the @domain.co.uk suffix.

This appears to work fine for people like John Smith or Jane Simpson, however, some people have more complicated names.
If there is someone with a name like Anton Du Chocolat, it ends upasADu@domain.co.uk.
I've even got someone with a name like this: Jean-Luc De Pompier.

I was wondering if anyone has any insight as to how I might deal with more complicated names like this?

Any help you can offer would be greatly appreciated.
Posts: 1
Joined: Wed Oct 12, 2016 3:21 pm

Re: turning full names into email addresses

Postby therube » Thu Oct 13, 2016 3:54 pm

Thinking your last case is ambiguous.

Is the first name (or first & middle) "Jean-Luc De" with a last name of "Pompier"
or is the first name "Jean-Luc" with a last name of "De Pompier"
Not sure how you would work through that?

Otherwise, if you accept that everything after the final space in the string is the last name, then maybe something like below will work (& of course this does fail in the case of Jean-Luc De Pompier).

Code: Select all
Match:  (.*)(\s)(.*)
Replace:  \1\3@domain.co.uk
Posts: 316
Joined: Mon Jan 18, 2016 6:23 pm

Return to Regular Expressions