Tapatalk

How to replace a string starting with @ and keeping only the last but one and last substring of dot separated string?

How to replace a string starting with @ and keeping only the last but one and last substring of dot separated string?

2
NewbieNewbie
2

    Mar 01, 2023#1

    Hello UE community. I've used UE for well over ten years editing MacroQuest macros for use with an MMORG called EverQuest and absolutely love UE. I even created my own UE wordfile years ago for the MacroQuest community. Anyway, this is the first time I have ever posted because I am trying to create a find/replace routine that is a bit out of my knowledge. So, I'm asking in the forums for a little help.

    I need to create an UltraEdit cleanup routine that will take a list of domains and remove the sub domains and the @ from the list. In my research, I think I could accomplish using Find/Replace functionality with Perl regular expressions, which I have used in the past, but this problem is a bit beyond my ability.

    Below is an example of the starting data and the ending data I wish to end up with. Could anyone give me a hand with this?
     
    Starting data

    Code: Select all

    @aaa.bbb.ccc.ddd.com
    @aaa.bbb.ccc.net
    @aaa.bbb.ru
    @aaa.info
     Ending data

    Code: Select all

    ddd.com
    ccc.net
    bbb.ru
    aaa.info

    6,685587
    Grand MasterGrand Master
    6,685587

      Mar 02, 2023#2

      There can be used for Unicode encoded text files (with UTF-8 or UTF-16 encoding) with domain string not percent encoded in the file the Perl search expression:

      @(?:[!$&'()*+,\-/0-9:;=?@A-Za-z_~\x{00a0}-\x{d7ff}\x{e000}-\x{fdcf}\x{fdf0}-\x{fffd}]+\.)*([!$&'()*+,\-/0-9:;=?@A-Za-z_~\x{00a0}-\x{d7ff}\x{e000}-\x{fdcf}\x{fdf0}-\x{fffd}]+\.[a-z]+)

      This Perl search expression is invalid for ASCII/ANSI encoded text files. The valid search expression is for such files:

      @(?:[!$&'()*+,\-/0-9:;=?@A-Za-z_~\x80-\xff]+\.)*([!$&'()*+,\-/0-9:;=?@A-Za-z_~\x80-\xff]+\.[a-z]+)

      If the files contain always domain strings consisting only of ASCII characters, the Perl search expression as shown below could be used independent on character encoding of the file.

      @(?:[!$&'()*+,\-/0-9:;=?@A-Za-z_~]+\.)*([!$&'()*+,\-/0-9:;=?@A-Za-z_~]+\.[a-z]+)

      The Perl replace expression is for all three search expressions \1 to back-reference the string found by the expression in the marking/capturing group while the string starting with @ and matched by the expression in the non-marking/non-capturing group with multiplier * for zero or more occurrences is ignored during the replace and removed from the file for that reason.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Mar 02, 2023#3

        Mofi, this is absolutely, positively amazing.

        As I mentioned, this is my first forum post in over a decade of using UltraEdit and you did a fantastic job. I had a feeling this was outside my experience zone, which it was, so I will be digesting your Perl search expressions to use as a learning experience.

        Thank you for your wonderful response, now I can see why you are the "Grand Master".