Delete certain amount of characters of e-mail address
-
Hello,
I have list of e-mail addresses and would like to delete to delete a certain amount characters within each e-mail address. I would like come from this:
to something like this:
I would like to keep the first 2 characters before the “.” as well as between the “.” and"@". Can someone help with the right replacement expression?
I am using the expression
(\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}\b)
to find e-mail addresses.
-
@o-Samusa-o said in Delete certain amount of characters of e-mail address:
Can someone help with the right replacement expression?
I looked up wikipedia for valid email address characters. That site also produced some valid addresses
https://en.wikipedia.org/wiki/Email_address
The list of valid characters was a lot longer than the one you provided, however I went with your list. You may want to visit the website and possibly amend your valid character list if you think it is prudent to do so. That will only be evident from the list you are working on. Bear in mind some of the characters aremetacharacters
and will need escaping by using the\
before the character.So the Replace function is
Find What:(?-s)([A-Z0-9_%+-]{2})[A-Z0-9_%+-]+(?=.*@)
Replace With:\1
The search mode MUST be “regular expression” and please have “wrap around” ticked.I used the below list (which came from the above site as valid addresses) with the regex above
disposable.style.email.with+symbol@example.com other.email-with-hyphen@example.com fully-qualified-domain@example.com user.name+tag+sorting@example.com x@example.com x.me@example.com x.me1@example.com example-indeed@strange-example.com " "@example.org (space between the quotes) "john..doe"@example.org (quoted double dot) mailhost!username@example.org (bangified host route used for uucp mailers) user%example.com@example.org
and got this resulting list:
di.st.em.wi@example.com ot.em@example.com fu@example.com us.na@example.com x@example.com x.me@example.com x.me@example.com ex@strange-example.com " "@example.org (space between the quotes) "jo..do"@example.org (quoted double dot) ma!us@example.org (bangified host route used for uucp mailers) us.co@example.org
Note at least 1 of the addresses was incorrectly changed. I mentioned the valid list of characters which include
!
so that’s why the one with this character was incorrectly changed. You mileage may vary depending on what list you use as valid characters.
I also need to qualify this solution, itONLY
works with 1 address on each line. Otherwise it will edit the domain portion of all email addresses but the last on a single line.Terry
-
@Terry-R said in Delete certain amount of characters of e-mail address:
Bear in mind some of the characters are metacharacters and will need escaping by using the \ before the character.
For more info on which characters need
escaping
within a character class (denoted by the[
and]
) read:
https://www.regular-expressions.info/charclass.html
specifically the paragraph titled
“Metacharacters Inside Character Classes”Terry