----------------------------------------------------------------------
--- Knud van Eeden --- 14 Juny 2007 - 10:23 pm -----------------------

TSE: Regular expression: Search: How to search with over multiple lines: 'string1.*string2'

---

This will search for string1 followed by another string2, possibly over
more than 1 line

--- cut here: begin --------------------------------------------------

 string1.*string2

--- cut here: end ----------------------------------------------------

===

--- cut here: begin --------------------------------------------------

FORWARD PROC Main()
FORWARD PROC PROCTextSearchExpressionRegularLineMultiSimple( STRING s1, STRING s2 )


// --- MAIN --- //

PROC Main()
 STRING s1[255] = ""
 STRING s2[255] = ""
 IF NOT Ask( "search string1 =", s1, GetFreeHistory( "ddd1" ) ) RETURN() ENDIF
 IF NOT Ask( "search string2 =", s2, GetFreeHistory( "ddd2" ) ) RETURN() ENDIF
 PROCTextSearchExpressionRegularLineMultiSimple( s1, s2 )
END

 Main()

// --- LIBRARY --- //

// library: text: search: expression: regular: line: multi: simple (filenamemacro=seartems.s) [version 1.0.6] [kn, ho, th, 14-06-2007 21:18:56]-[kn, ho, fr, 22-06-2007 13:51:22]
PROC PROCTextSearchExpressionRegularLineMultiSimple( STRING s1, STRING s2 )
 // e.g. PROC Main()
 // e.g.  STRING s1[255] = ""
 // e.g.  STRING s2[255] = ""
 // e.g.  IF NOT Ask( "search string1 =", s1, GetFreeHistory( "ddd1" ) ) RETURN() ENDIF
 // e.g.  IF NOT Ask( "search string2 =", s2, GetFreeHistory( "ddd2" ) ) RETURN() ENDIF
 // e.g.  PROCTextSearchExpressionRegularLineMultiSimple( s1, s2 )
 // e.g. END
 // e.g.
 // e.g.  Main()
 //
 // ===
 //
 // For example
 //
 // search minimum closure a.*b over multiple lines
 //
 // Given this 2 lines:
 //
 // a..........a....b.b......b......a....b.....a.........b....a.....a
 // .......a.....b
 //
 // It highlights and finds
 //
 // a..........a....b
 //
 //            a....b
 //
 //                                 a....b
 //
 //                                            a.........b
 //
 //                                                           a.....a
 // .......a.....b
 //
 //                                                                 a
 // .......a.....b
 //
 //        a.....b
 //
 INTEGER stopB = FALSE
 INTEGER foundString1B = FALSE
 INTEGER foundString2B = FALSE
 INTEGER messageBoxI = 0
 INTEGER noMessageBoxB = FALSE
 INTEGER blockAttrOldI = 0
 INTEGER cursorInBlockAttrOldI = 0
 INTEGER menuSelectAttrOldI = 0
 //
 Set( Break, ON )
 //
 UnMarkBlock() // unmark any already existing block
 //
 blockAttrOldI = SET( BlockAttr, Color( Intense Bright Black on Yellow ) ) // set the color of the highlighted block
 cursorInBlockAttrOldI = SET( CursorInBlockAttr, Color( Intense Bright Black on Yellow ) ) // set the color of cursor line in the highlighted block. Choose to let the color of this cursor line be the same as the block color itself, so not distinguisable
 //
 REPEAT
  foundString1B = LFind( s1, "ix" ) // search for string1 (possibly a regular expression)
  IF ( foundString1B )
   //
   PushPosition() // store start position of next search, at character1 of string1
   //
   MarkStream() // string1 found, start marking block
   //
   Right() // go to character2 of string1 to be sure you do not find string2 as string1 (if they are equal)
   //
   foundString2B = LFind( s2 + "\c", "ix" ) // starting from the current position of string1, search for (possibly again and again for the same) string2 (possibly a regular expression)
   IF ( foundString2B )
    Left() // because cursor was set at first character after string2, put it back on last character of string2 (by going back one character to the left)
    MarkStream() // '.*string2' found, end marking block
    ScrollToTop() // show the result at the top of the current window
    GotoBlockBegin() // put cursor at begin of block
    UpdateDisplay() // and make sure you see the last updated window
    messageBoxI = MsgBox( "Search", s1 + ".*" + s2, _YES_NO_ ) // choose to stop or continue
    noMessageBoxB = ( messageBoxI == 2 ) // 'no' selected in messagebox
    PopPosition() // go back to character1 of string1
    Right() // to initialize next search of string1 (and avoiding finding string1 again) go to character2 of string1
    IF NOT ( noMessageBoxB )
     UnMarkBlock() // initialize the block again
    ENDIF
   ENDIF
  ENDIF
  stopB = ( NOT foundString1B ) OR ( NOT foundString2B ) OR ( noMessageBoxB )
 UNTIL stopB
 IF ( NOT foundString1B ) OR ( NOT foundString2B )
  menuSelectAttrOldI = SET( MenuSelectAttr, Color( Intense Bright Black on Red ) ) // show visually clearly with red color that it is the end of the search
  MsgBox( "Search", "Not found" )
  SET( MenuSelectAttr, menuSelectAttrOldI ) // put back to original color
  UnMarkBlock() // clear the block, because not found
 ENDIF
 SET( BlockAttr, blockAttrOldI ) // put back the original block color
 SET( CursorInBlockAttr, cursorInBlockAttrOldI ) // put back the original cursor line in block color
 //
END


--- cut here: end ----------------------------------------------------

===

Internet: see also:



===

Image: see also:


----------------------------------------------------------------------