Find the last occurrence of a string in a file.

Find the last occurrence of a string in a file.

5
NewbieNewbie
5

    May 20, 2020#1

    Code: Select all

    switch(?!.*switch)
    Finds the last occurrence of a word on a line, but the file might be several thousand lines long, and I want to find the last occurrence in the entire file.
    In my test file, I used:

    Code: Select all

    switch(?![^¢]*switch)
    But in real life, I cannot guarantee that the cents symbol will never occur.

    What is the proper way to do this?

    6,603548
    Grand MasterGrand Master
    6,603548

      May 21, 2020#2

      Press Ctrl+End to move caret to end of a file and use a simple, non-regular expression Find opened with Alt+F3 (not Quick Find as executed by default with Ctrl+F) for switch with clicking on button Previous or pressing Alt+P.
      Best regards from an UC/UE/UES for Windows user from Austria

      18672
      MasterMaster
      18672

        May 21, 2020#3

        If you really need to use regexp for whatever reason:

        (?s).*\Kswitch

        5
        NewbieNewbie
        5

          May 21, 2020#4

          The file is a log file and I'm polling it.
          So I was hoping to just hit F3 and find the last occurrence which is often buried in a hundred or more lines of other stuff

          When I use the suggestion provided, it finds the last, but oddly in one rather long file, it also returned an occurrence in the middle.
          I suspect that there is a buffer length involved.
          The file is 120K, and I was using it as a test after it had been closed.

          Later today, I'll try it on a live log file.