• Login
Community
  • Login

Delete certain amount of characters of e-mail address

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
3 Posts 2 Posters 1.1k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O
    o-Samusa-o
    last edited by Aug 21, 2020, 5:35 AM

    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:

    name.surname@domain.com

    to something like this:

    na.su@domain.com

    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.

    T 1 Reply Last reply Aug 21, 2020, 7:29 AM Reply Quote 0
    • T
      Terry R @o-Samusa-o
      last edited by Terry R Aug 21, 2020, 7:31 AM Aug 21, 2020, 7:29 AM

      @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 are metacharacters 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, it ONLY 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

      1 Reply Last reply Reply Quote 2
      • T
        Terry R
        last edited by Aug 21, 2020, 9:47 AM

        @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

        1 Reply Last reply Reply Quote 1
        2 out of 3
        • First post
          2/3
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors