subsoft
subsoft

Reputation: 99

Getting lastname from email using regex replace option

I would like to get lastname from an email address:

Sample:

[email protected] -> jane
[email protected] -> bell

I have tried this

(.*)@.*

Replace

$1

Which gives me:

john.bell

NOTE: I have to use replace option

Thanks for your help

Upvotes: 1

Views: 48

Answers (1)

ndnenkov
ndnenkov

Reputation: 36100

Get all word characters before the following @ sign:

\w+(?=@)

See it in action


If for some reason you really want to use replace you could do:

\w+\.|@.*

Replace with empty string.

See it in action

The idea is to replace either word characters followed by a dot or everything after the @ sign (included).

Upvotes: 1

Related Questions