#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?mx)\G #anclado a \A o fin de última coincidencia" & @CRLF & _
"( #Grupo 1: Caracteres previos" & @CRLF & _
" [^\h\\'\v]*+ # Todo menos caracteres especiales" & @CRLF & _
" (?: # Repetir infinitas veces" & @CRLF & _
" (?: # Alternativas:" & @CRLF & _
" (?!^)\h # a. espacio simple que no" & @CRLF & _
" (?!\h|$) # está al ppio ni al final" & @CRLF & _
" | \v # b. línea nueva" & @CRLF & _
" | \\. # c. cualquier escape" & @CRLF & _
" | '[^'\\]*+ # d. comillas" & @CRLF & _
" (?:(?:''|\\.)[^'\\]*)* " & @CRLF & _
" ' #" & @CRLF & _
" ) #" & @CRLF & _
" [^\h\\'\v]*+ # Seguido de más texto no especial" & @CRLF & _
" )* #" & @CRLF & _
") #(fin G1)" & @CRLF & _
"(?: #Espacios:" & @CRLF & _
" ^\h+ # a. al ppio de la línea" & @CRLF & _
"| \h+(\h|$) # b. en el medio o al final" & @CRLF & _
") #"
Local $sString = " select * , fooo , " & @CRLF & _
" a, " & @CRLF & _
"b," & @CRLF & _
"c" & @CRLF & _
" from" & @CRLF & _
"table" & @CRLF & _
"where a = 'a b'" & @CRLF & _
" or campo = 'borra los espacios \'no?'" & @CRLF & _
"and c = 1;"
Local $sSubst = "$1$2"
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