replace all text that follows something

replace all text that follows something

4
NewbieNewbie
4

    Sep 14, 2006#1

    hello

    I want to scan each line (not sentence or anything else) and delete (replace with nothing) all visible characters (eg numbers, symbols, letters, but not paragraph ends) that follow (that is at the right of) the first occurance in line of this: ',something' (without quotemarks)

    thanks

    344
    MasterMaster
    344

      Sep 14, 2006#2

      Hm, an example was nice, but if I understood it right, a macro like this should do the job:

      Code: Select all

      InsertMode
      ColumnModeOff
      HexOff
      UnixReOff
      Loop 
      Find ",something"
      IfFound
      Key RIGHT ARROW
      Key LEFT ARROW
      StartSelect
      Key END
      EndSelect
      Key DEL
      Else
      ExitLoop
      EndIf
      EndLoop
      
      Macro property "repeat if nothing found" has to be set.

      Before:
      bla ,something fghg hgfh
      bla something without something else
      bla ,something and something else
      bla ,something and something else
      bla something without something else
      bla ,something and something else
      Afterwards
      bla ,something
      bla something without something else
      bla ,something
      bla ,something
      bla something without something else
      bla ,something
      rds Bego
      Normally using all newest english version incl. each hotfix. Win 10 64 bit

      4
      NewbieNewbie
      4

        Sep 14, 2006#3

        thanks

        I saved the above code in a text file but I cant make it work as macro (not valid macro)

        344
        MasterMaster
        344

          Sep 14, 2006#4

          Why text file?
          Copy the statements above with ctrl-c, goto Ultraedit, open say "New Macro" in the macro menu.
          Now just give the macro a name, set the property as described above and paste the code (ctrl-v) there.
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          4
          NewbieNewbie
          4

            Sep 14, 2006#5

            thanks

            can you tell me please the opposite? I mean to delete previous things

            thanks

            344
            MasterMaster
            344

              Sep 14, 2006#6

              quite similar:

              InsertMode
              ColumnModeOff
              HexOff
              UnixReOff
              Loop
              Find ",something"
              IfFound
              Key Ctrl+LEFT ARROW
              StartSelect
              Key HOME
              EndSelect
              Key DEL
              Else
              ExitLoop
              EndIf
              EndLoop


              But in your specific example, you have to place a
              "KEY LEFT ARROW"
              after "Key Ctrl+LEFT ARROW"
              because comma and something are "2 words"

              Also "Key HOME" is dependant of your UE setting, if KEY HOME is always pointing to column 1 or not. Normally, it should work.
              If not, search for "KEY HOME" macro in this forum.

              rds Bego
              Normally using all newest english version incl. each hotfix. Win 10 64 bit

              6,603548
              Grand MasterGrand Master
              6,603548

                Sep 14, 2006#7

                Hi Bego!

                Why using macros for this. A single regular expression replace ALL can do the same.

                Delete everthing after ',something' in UltraEdit style:

                Find: ,something*$
                Replace: ,something


                Delete everthing before ',something' in UltraEdit style:

                Find: %*,something
                Replace: ,something


                Delete everthing after ',something' in Unix/Perl style:

                Find: ,something.*$
                Replace: ,something


                Delete everthing before ',something' in Unix/Perl style:

                Find: ^.*,something
                Replace: ,something
                Best regards from an UC/UE/UES for Windows user from Austria

                344
                MasterMaster
                344

                  Sep 14, 2006#8

                  Hi Mofi, you're right!
                  But why the easy way if there is a complicated solution ? ;-)
                  I think I was in a macro blindness ;-)
                  ...or a little regexp angry cause perl regexps work so badly.

                  rds Bego
                  Normally using all newest english version incl. each hotfix. Win 10 64 bit

                  6
                  NewbieNewbie
                  6

                    Delete ALL characters before or after a string

                    Sep 04, 2007#9

                    I'm using UltraEdit 13.10a+1, I am using the UE style for regexes.

                    Question:

                    How do I delete ALL characters - inlcuding line breaks and invisible characters - before a given string? And how do I delete ALL characters - including line breaks and invisibles - after a given string?

                    For example:

                    I want to delete all the characters before the HTML tag:
                    <div class="tablejdb"> in my webpage. THEN I want to delete all the characters after the <div class="text"> HTML tag in my webpage.

                    Yes, I already read Mofi's solution to a similar problem, but this does not work for me because it does not delete line breaks and invisible characters preceding or succeeding the string.

                    6,603548
                    Grand MasterGrand Master
                    6,603548

                      Re: Delete ALL characters before or after a string

                      Sep 04, 2007#10

                      See my macro at Run Macro on all files within folder. You can also use FindInFiles option Recursive if the files are spread over multiple directories.

                      Or open all files and use my macro at following macro.

                      Loop
                      IfNameIs ""
                      ExitLoop
                      EndIf
                      Top
                      StartSelect
                      Find MatchCase Select "<div class="tablejdb">"
                      IfSel
                      Key Ctrl+LEFT ARROW
                      Key Ctrl+LEFT ARROW
                      Key Ctrl+LEFT ARROW
                      Key Ctrl+LEFT ARROW
                      Key Ctrl+LEFT ARROW
                      Key LEFT ARROW
                      Delete
                      EndIf
                      Find MatchCase "<div class="text">"
                      IfFound
                      EndSelect
                      Key LEFT ARROW
                      Key RIGHT ARROW
                      SelectToBottom
                      Delete
                      CloseFile Save
                      EndLoop

                      You need a macro for that job because the simple regular expression replaces I posted are only for deleting everything before and after a string within a line only. You want delete blocks.
                      Best regards from an UC/UE/UES for Windows user from Austria

                      6
                      NewbieNewbie
                      6

                        Re: Delete ALL characters before or after a string

                        Sep 04, 2007#11

                        Thanks, it worked, im happy. I've learned a lot today

                        236
                        MasterMaster
                        236

                          Re: Delete ALL characters before or after a string

                          Sep 05, 2007#12

                          You could use a regular expression instead of a macro in a "replace in files" command, too. Since the dot (.) doesn't match line breaks in UE, and there's no way I know of to change that behaviour, I needed to use a kludge to make it work. Probably there's a more elegant way to do it.

                          What you need is a character that you know will NOT occur in your file. Say a character like ÿ (ASCII 255).

                          Then you can search for

                          Code: Select all

                          [^ÿ]*(<div class="tabledb">[^ÿ]*?<div class="text">)[^ÿ]*
                          and replace with

                          Code: Select all

                          \1
                          Enable Perl style regular expressions for this search.

                          HTH,
                          Tim

                          6,603548
                          Grand MasterGrand Master
                          6,603548

                            Re: Delete ALL characters before or after a string

                            Sep 20, 2007#13

                            I know the method suggested by Tim and I have also posted it somewhere. But this one is dangerous.

                            In the past using this method to search for something which does not exist until a specified string is found produced not the result I (we) would expect. I don't know if this still happens, but in previous versions of UltraEdit with the UltraEdit regex engine the [~ÿ]++ regular expression selected everything to last occurence of the next specified string which is here <div class="tabledb">. I would have expect that [~ÿ]++ stops on first occurence of <div class="tabledb"> and not on last, but that was not the case.

                            Second be careful with tagged expressions. I don't know if there is a maximum limit for the number of bytes of a found tagged string. If UE/UES works with static arrays for the found tagged strings a regular expression like (<div class="tabledb">[^ÿ]*?<div class="text">) could result in a loss of needed data when the number of bytes is to large. That's very dangerous especially in a Replace In Files operation which cannot be undone.

                            That's the reason why I use for block deletions the Find Select "..." method. It's safe.
                            Best regards from an UC/UE/UES for Windows user from Austria