Delete only 1st word A in front of word B

Delete only 1st word A in front of word B

19
Basic UserBasic User
19

    Jun 19, 2006#1

    Hello,

    is it possible to do the following with (Perl)-RegEx?
    Delete only the first special word A in front of another special word B and add a TAB(\t).

    Before:
    This is a wordA sentence with wordA followed by wordB
    Another one with wordA and then wordB

    After;
    This is a wordA sentence with\tfollowed by wordB
    Another one with\tand then wordB

    6,686585
    Grand MasterGrand Master
    6,686585

      Jun 20, 2006#2

      Don't know if it is possible with a Perl regex. But the following macro will do it independent of the the macro property Continue if a Find with Replace not found.

      But only if there is always wordA before an occurence of wordB. If wordB exists also without wordA in the same line/paragraph/file? - you did not clearly describe that - it will search up for any wordA and replace it with a tab and so will replace all wordA by a tab before the first occurence of wordB without wordA.

      InsertMode
      ColumnModeOff
      HexOff
      Loop
      Find MatchCase MatchWord "wordB"
      IfFound
      Find MatchCase MatchWord Up "wordA"
      Replace "^t"
      IfNotFound
      ExitLoop
      EndIf
      Find MatchCase MatchWord "wordB"
      Else
      ExitLoop
      EndIf
      EndLoop
      Best regards from an UC/UE/UES for Windows user from Austria

      19
      Basic UserBasic User
      19

        Jun 20, 2006#3

        Servus Mofi,

        Actually there are SEVERAL LINES, each containing at least one wordA and one wordpartB. I want to replace wordA including the spaces before after wordA with a TAB.

        Before:

        Code: Select all

        This is a wordA line with wordA followed by wordpartBandrestofword.
        Another line with wordA and then wordpartBwithanotherrest.
        After:

        Code: Select all

        This is a wordA line withTABfollowed by wordpartBandrestofword.
        Another line withTABand then wordpartBwithanotherrest.
        I just had to kick out "Matchword" of your Macro and it runs!
        But shouldn't replace the Macro from first to last line of my file in one run, with "Run Macro once"? (cause of the endless loop in the Macro).

        6,686585
        Grand MasterGrand Master
        6,686585

          Jun 20, 2006#4

          thomasm76 wrote:I just had to kick out "Matchword" of your Macro and it runs!
          Yes, you have to remove MatchWord and insert 2 spaces at the find string for wordA.
          thomasm76 wrote:But shouldn't replace the Macro from first to last line of my file in one run, with "Run Macro once"? (cause of the endless loop in the Macro).
          Yes, the macro replaces all wordA before wordB if you run it from top of the file. The macro does not contain the command Top. So it is executed from current cursor position till the position where wordB is found last (or " wordA " is not found upwards). There is no need to specify how often the macro should run and do the replacement.
          Best regards from an UC/UE/UES for Windows user from Austria