Entry
TSE: File: Search: How to search/replace over multiple lines? [dehyphenation / regular expression]
Aug 26th, 2005 16:19
Knud van Eeden,
----------------------------------------------------------------------
--- Knud van Eeden --- 19 May 2021 - 03:27 pm ------------------------
TSE: File: Search: How to search/replace over multiple lines?
[dehyphenation / regular expression]
---
Method: Search first and hold, then search further forward
(possibly multiple lines further)
1. You first search for the 1st expression
1. When found you hold that position
1. You then search forward for the 2nd expression
(possibly multiline)
1. When this 2nd expression is found
1. do something
1. Go back to the hold position,
and continue from there again
---
Steps: Overview:
1. -Create e.g. the following macro
--- cut here: begin --------------------------------------------------
// library: block: search: line: multi: hold: forward [kn, ri, th, 19-
05-2005 15:46:29]
PROC PROCBlockSearchLineMultiHoldForward( STRING searchHoldS, STRING
searchForwardS, STRING searchOptionHoldS, STRING searchOptionForwardS,
INTEGER lineDifferenceGivenI, STRING caseS )
// ---
//
// before:
//
// --- cut here: begin ---------------------------------------------
//
// This is an example of de-
// hyphenation.
// This might be use-
// ful, in OCR for ex-
// ample.
//
// --- cut here: end ------------------------------------------------
//
// ---
//
// after:
//
// --- cut here: begin ----------------------------------------------
//
// This is an example of dehyphenation.
// This might be useful, in OCR for example.
//
// --- cut here: end ------------------------------------------------
INTEGER rowHoldI = 0
INTEGER rowForwardI = 0
INTEGER lineLastB = FALSE
//
IF NOT IsBlockInCurrFile()
Warn( "please mark a block" )
RETURN() ENDIF
//
PushPosition()
//
GotoBlockBegin()
//
WHILE ( LFind( searchHoldS, searchOptionHoldS ) ) AND IsCursorInBlock
() AND ( NOT lineLastB )
rowHoldI = CurrLine()
PushPosition()
IF LFind( searchForwardS, searchOptionForwardS )
rowForwardI = CurrLine()
IF ( lineDifferenceGivenI == ( rowForwardI - rowHoldI ) )
CASE caseS
WHEN "operation: dehyphenate"
// do something
PopPosition()
Left() // go back to the '-'
DelChar() // remove the '-'
JoinLine()
WHEN "operation: remove line"
// do something
WHEN "operation: add line"
// do something
OTHERWISE
Warn( "PROCBlockSearchLineMultiHoldForward" + " " + caseS + " "
+ "unknown case" )
RETURN()
ENDCASE
ENDIF
ELSE
PopPosition()
ENDIF
lineLastB = ( CurrLine() == NumLines() )
ENDWHILE
//
PopPosition()
//
END
//
PROC Main()
PROCBlockSearchLineMultiHoldForward( "[a-zA-Z]-$\c", "^[a-zA-Z][a-zA-
Z0-9]*{$|[ .,!?:;" + '"' + "']}", "x", "x", 1, "operation:
dehyphenate" ) // delete last character and join current line with
next line
END
//
<F12> Main
--- cut here: end ----------------------------------------------------
2. -Highlight the block in which to search/replace
3. -Run this macro
---
---
Internet: see also:
---
TSE: File: Search/Replace: Regular expression: Does a regular
expression search span multiple lines?
http://www.faqts.com/knowledge_base/view.phtml/aid/32697/fid/865
---
TSE: Text: Wordwrap: Hyphen: Remove: How to dehyphenate wordwrapped
text? ['-' / join]
http://www.faqts.com/knowledge_base/view.phtml/aid/36316/fid/904
----------------------------------------------------------------------