#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)(.{1,80}\S)(?:[\r\n\f\v ]+|$)"
Local $sString = "--- 0---|--- 10---|--- 20---|--- 30---|--- 40---|--- 50---|--- 60---|--- 70---|--- 80---|--- 90---|" & @CRLF & _
"123456789|123456789|123456789|123456789|123456789|123456789|1 23456789|123456789|123456789|123456789|" & @CRLF & _
"" & @CRLF & _
"" & @CRLF & _
"SELECT" & @CRLF & _
" tbl_Hex.Hex_ID" & @CRLF & _
" ,tbl_Generic_Tool.Generic_Code AS [Generic Code]" & @CRLF & _
" ,tbl_ref_Generic_Type.Generic_Type AS [Generic Type]" & @CRLF & _
"FROM tbl_ref_Location" & @CRLF & _
" RIGHT JOIN ((tbl_ref_Generic_Type" & @CRLF & _
" INNER JOIN tbl_Generic_Tool ON tbl_ref_Generic_Type.Generic_Type_ID = tbl_Generic_Tool.Generic_Type_ID)" & @CRLF & _
" INNER JOIN (tbl_ref_Building" & @CRLF & _
" INNER JOIN tbl_Hex ON tbl_ref_Building.Building_ID = tbl_Hex.Building_ID) ON tbl_Generic_Tool.Generic_ID = tbl_Hex.Generic_ID) ON tbl_ref_Location.Location_ID = tbl_Hex.Location_ID" & @CRLF & _
"GROUP BY" & @CRLF & _
" tbl_Hex.Hex_ID" & @CRLF & _
" ,tbl_Hex.Hex_No" & @CRLF & _
" ,tbl_ref_Building.Building_Abbrev" & @CRLF & _
" ,tbl_ref_Location.Location" & @CRLF & _
" ,tbl_Generic_Tool.Generic_Code" & @CRLF & _
" ,tbl_ref_Generic_Type.Generic_Type" & @CRLF & _
"ORDER BY" & @CRLF & _
" tbl_Hex.Hex_No;" & @CRLF & _
""
Local $sSubst = "$1\r\n"
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