#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(.)\n(?!\n)"
Local $sString = "I have a text file where lines are trimmed by newline characters." & @CRLF & _
"I want to strip out those single newlines and replace with simple spaces." & @CRLF & _
"But I do not want the double newlines affected." & @CRLF & _
"" & @CRLF & _
"This line should start after 2 line breaks." & @CRLF & _
"Everything I try inevitably ends up affecting those double new lines too." & @CRLF & _
"" & @CRLF & _
"This line should also start after 2 line breaks." & @CRLF & _
"This can be solved using lookaheads."
Local $sSubst = "\1 "
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm