>Source = "SELECT aField, bField AS Field2, [, ]+PADR(cField,2) AS cField ..." >Result: "SELECT aField,"+CHR(13)+" bField AS Field2,"+CHR(13)+" [, ]+PADR(cField,2) AS cField ..." >>
*-------------------------------------------------------------------------- #define TRUE .T. #define FALSE .F. function do_it() local SearchFor, ReplaceBy SearchFor = ' *, *' ReplaceBy = ', ' +chr(13)+chr(10) ?FunctionWithoutName("SELECT aField, bField AS Field2, [, ]+PADR(cField,2) AS cField ...", SearchFor, ReplaceBy ) ?FunctionWithoutName("select sum(a+b), sum(c+d) as eee, sum(e+f)", SearchFor, ReplaceBy ) ?FunctionWithoutName("select sum(a+b), sum(c+d) + [123['] as eee, sum(e+f)", SearchFor, ReplaceBy ) endfunc *-------------------------------------------------------------------------- function FunctionWithoutName(Source, SearchFor, ReplaceBy) local RegExp, Match, i, Result, s, c, ToDo, l, n local RegExp2, Match2 RegExp = CreateObject('VBScript.RegExp') RegExp.IgnoreCase = FALSE RegExp2 = CreateObject('VBScript.RegExp') s = source && (1) replace '', "", [] and everything between with dots && [ " ' do while TRUE RegExp.Pattern = '[' + [['"] + ']' RegExp.Global = FALSE Match = RegExp.Execute(s) do case case !empty(Match.Count) i = Match.Item[0].FirstIndex c = Match.Item[0].Value do case case inlist(c, ['], ["]) RegExp.Pattern = c RegExp.Global = TRUE Match = RegExp.Execute(s) do case case (Match.Count < 2) assert FALSE message 'expr not well formed' return FALSE otherwise l = Match.Item[1].FirstIndex - i + 1 s = stuff(s, i+1, l, repl('.', l)) endcase otherwise RegExp.Pattern = '\]' RegExp.Global = FALSE Match = RegExp.Execute(s) do case case empty(Match.Count) assert FALSE message 'expr not well formed' return FALSE otherwise l = Match.Item[0].FirstIndex - i + 1 s = stuff(s, i+1, l, repl('.', l) ) endcase endcase otherwise exit endcase enddo && (2) ( ) nested, replace (...) with ..... RegExp.Global = TRUE RegExp.Pattern = '\(' Match = RegExp.Execute(s) RegExp2.IgnoreCase = FALSE RegExp2.Global = FALSE RegExp2.Pattern = '\)' for n = Match.Count - 1 to 0 step -1 i = Match.Item[n].FirstIndex + 1 Match2 = RegExp2.Execute( substr(s, i+1 )) do case case empty(Match2.Count) assert FALSE message 'expr not well formed' return FALSE otherwise l = Match2.Item[0].FirstIndex + 2 s = stuff(s, i, l, repl('.', l)) endcase endfor && (3) Final RegExp.Global = TRUE RegExp.Pattern = SearchFor Match = RegExp.Execute(s) for i = Match.Count - 1 to 0 step -1 Source = stuff(Source, Match.Item[i].FirstIndex + 1, Match.Item[i].Length, ReplaceBy) endfor return Source endfunc *--------------------------------------------------------------------------