Find start of line over two consecutive lines

Find start of line over two consecutive lines

5
NewbieNewbie
5

    Dec 28, 2012#1

    I have an array with mostly 6 lines:

    01 ...
    02 ...
    03 ...
    04 ...
    05 ...
    06 ...
    01 ...
    02 ...

    etc.

    Every so often the sixth line is missing:

    01 ...
    02 ...
    03 ...
    04 ...
    05 ...

    01 ...

    I want to find the five line sets so I tried to Find %05%01 but I get no results.

    How do I find start of lines over two consecutive lines?

    6,603548
    Grand MasterGrand Master
    6,603548

      Dec 29, 2012#2

      The UltraEdit regular expression character % for beginning of a line can be used only once in a search string at beginning.

      The right UltraEdit regular expression for a file with DOS line terminators for your use case would be %05*^p01

      But there is a problem with this expression. It matches also

      05 ...
      06 ...
      01


      although it should match only

      05 ...
      01

      UltraEdit regular expression character * should match any number of occurrences of any character except newline characters. And this works, but not if * is left of ^p in a search string. Then the expression * becomes greedy and matches also newline characters. I know about this bug in the UltraEdit regular expression engine very well.

      However, there is a very simple workaround for this bug: instead of * the expression ?++ is used which means also zero or more occurrences of any character except newline characters and which does not have the unwanted greedy behavior.

      So %05?++^p01 is the UltraEdit regular expression search string you need for this task.


      Alternatively the UltraEdit regexp search strings %05[~^p]++^p01 or %05[~^r^n]++^p01 could be used too.
      [~^p]++ respectively [~^r^n]++ means NOT a carriage return or line-feed character zero or more times which is equal the expression ?++.


      The search string would be ^05.*\r\n01 or alternatively ^05[^\r\n]*\r\n01 with the Perl regular expression engine.


      Either the search string ^05[^\r\n]*\r\n01 or the string ^05[^\p]*\p01 must be used with the legacy Unix regular expression engine.
      The Unix regexp search strings ^05.*\r\n01 or ^05.*\p01 show the same greedy behavior as UltraEdit regexp search string %05*^p01.

      5
      NewbieNewbie
      5

        Jan 03, 2013#3

        Bingo! The regular expression works great!

        Thanks for your help!