delete everything after the last semicolon on a line

delete everything after the last semicolon on a line

60
Advanced UserAdvanced User
60

    Jul 28, 2008#1

    I have lines like this

    this is a test;delete all of this
    test line two; this I want ; delete all of this
    regular epxressions;are;great; when; you;know;how;to;use;them;delete this stuff


    I want to delete after the last semicolon on each line.
    I am using UE 14.10.1.0.1024

    119
    Power UserPower User
    119

      Jul 28, 2008#2

      Using Perl-style regular expressions:
      Find What: [^;]*$
      Replace With: ^p

      60
      Advanced UserAdvanced User
      60

        Jul 28, 2008#3

        This results in the following


        this is a test;test line two; this I want ;regular epxressions;are;great; when; you;know;how;to;use;them;


        Not what I was hoping for as a result. I want each line to just lop off the trailing stuff after the last semicolon.


        looking more for this kind of result


        this is a test;
        test line two; this I want ;
        regular epxressions;are;great; when; you;know;how;to;use;them;

          Jul 29, 2008#4

          Fantastic!!!!!

          Could you please explain the expression so I understand how it works.

          Thanks a million

          6,606548
          Grand MasterGrand Master
          6,606548

            Jul 29, 2008#5

            I suggest a Perl regular expression search string [^;\r\n]+$ and an empty replace string. That would not change the current line ending format.

            There is a help page about Perl regular expression in help of UltraEdit, but here is a short explanation.

            Square brackets [...] means find any character specified inside the brackets.

            If the first character after [ is ^ then the meaning is reversed. So [^...] means find any character except those specified inside the brackets.

            \r is the character code for the character carriage return.
            \n is the character code for the character line-feed.

            So [^;\r\n] means find 1 character which is not a semicolon, not a carriage return and not a line-feed.

            The + after the bracket means find the previous expression 1 or more times (* means 0 or more times). Because the previous expression means any character except semicolon, CR and LF, this regular expression selects now all strings not containing these 3 characters. But we want to find only those strings on end of line.

            So the last regex character $, which means end of line without selecting the line ending characters, anchors the search to the end of the line.
            Best regards from an UC/UE/UES for Windows user from Austria

            236
            MasterMaster
            236

              Jul 29, 2008#6

              Very good improvement, Mofi.

              I would suggest yet another modification:

              Search for
              (?<=;)[^;\r\n]+$

              and replace with nothing. The positive lookbehind expression (?<=;) makes sure that there is in fact a semicolon after which to delete the rest of the line. Otherwise, lines that don't contain a semicolon will be deleted entirely (save the CRLF).

              If that's what is requested - but sklad2 wrote it that way :)

              60
              Advanced UserAdvanced User
              60

                Jul 30, 2008#7

                It is working great!!!!

                Code: Select all

                (?<=;)[^;\r\n]+$
                This is the one I am currently running.

                I am thinking about getting Regex buddy. I hope this will help my regex skills :mrgreen:

                Thanks for all of the great help with regular expression!!!!!!!! :D