Back to the headlock
You nicely pointed out the problem : how to make regex versatile enough to work on all files BUT secure enough to get invariable results
For $T & $F in Example 2 , footnotes can be first deleted selectively, then the newlines can be inserted including an additional condition ($T not preceded by $F)
For Example 3, to match both "$=<$=T3*1" and "$=<$=T4*42_USC_300AA-11" the expression may be done a bit less selective : (T\d\*\S+\s*) this should work as long as the sequences to match end with a space
Sooo... version 2 :
FileDelete(@ScriptDir & '\output.txt')
$a = FileRead(@ScriptDir & '\ahihi.txt')
; delete footnotes, selective
$a = StringRegExpReplace($a, '(\$%\$\?\$%[\s-]+(End\s+)?Footnotes[\s-]+)', "")
; insert a newline before $00, $T etc if they are not preceded by start of text, colon or $F
$a = StringRegExpReplace($a, '(?<!^|:|\$F)(?=\$(?|00|01|03|10|20|25|30|40|45|110|115|120|F|T|200|220))', @crlf)
; delete all content behind $00: and \$200:
$a = StringRegExpReplace($a, '(?<=\$00:|\$200:).+', "")
; delete whole lines $01, $03, $30 including newlines
$a = StringRegExpReplace($a, '\$(?|01|03|30):.+\R', "")
; delete $=< , $=T3*1 , $=T4*42_USC_300AA-11 , $=L01836000613000341*000341 , $=P1298*n , $=>
$a = StringRegExpReplace($a, '\$=(?|<|(T\d\*\S+\s*)|([LP]\d+\*\d+)|>)', "")
; insert a newline before $%$?$% , and before $T & $M if preceded by letter+colon
$a = StringRegExpReplace($a, '(?=\$%\$\?\$%)|((?<=[a-z]:)(?=\$[TM]))', @crlf)
; move $=S from end of line to start of next line
$a = StringRegExpReplace($a, '(\$=S)(\R)', "$2$1")
; OPTIONALS
; replace unwanted newlines in text parts by a horizontal space
$a = StringRegExpReplace($a, '(\$T|\$%\$\?\$%)\V+?\K(?<=\w|\.)\R(?=\h?\w)', " ")
; replace multi horizontal spaces by only one
$a = StringRegExpReplace($a, '\h+', " ")
; remove horizontal space between $I and $U
$a = StringRegExpReplace($a, '(?<=\$I)\h+(?=\$U)', "")
FileWrite("output.txt", $a)