Code: Select all
RegExMatch(script, "s)/\*(.*?)\*/", match)
MsgBox % match
Code: Select all
RegExMatch(script, "s)/\*(.*?)\*/", match)
MsgBox % match
I agree. Both above scripts seem to mangle if not careful.swagfag wrote: ↑23 Jan 2022, 05:55theres more to parsing comments than just checking /* and ;, particularly if u actually care about not mangling the script in the process
u may be able to rip ahk2exe's guts and repurpose them https://github.com/AutoHotkey/Ahk2Exe/blob/master/ScriptParser.ahk#L33-L175
Code: Select all
B:="/*", E:="*/" ,Z:=""
;---------------
gosub,a1
Loop,parse,e4,`n,`r
{
x:= A_LoopField
x=%x%
stringmid,p,x,1,1
if (p=";")
continue
If InStr(x,B)
H1=1
If InStr(x,E)
{
H1=0
continue
}
if (H1="1")
continue
z .= x . "`r`n"
}
msgbox,%z%
z=
return
;----------------------
A1:
e4=
(
Line_01
Line_02
Line_03
/*fff ggg hhh */
Line_04
Line_05
/*
comment
comment
comment
*/
Line_06
Line_07
/* comment
comment
comment */
Line_08
Line_09;no comment
Line_10
;comment
Line_11
Line_12 ; comment ( this not removed )
; comment
Line_13
Line_14
)
return
;=======================================================================
Code: Select all
Line_01
Line_02
Line_03
Line_06
Line_07
Code: Select all
B:="/*", E:="*/" ,Z:=""
F1=%a_scriptdir%\test21.ahk
;---------------
gosub,a1
Loop,parse,e4,`n,`r
{
x:= A_LoopField
x=%x%
stringmid,p,x,1,1
if (p=";")
continue
If InStr(x,B)
H1=1
If InStr(x,E)
{
H1=0
continue
}
if (H1="1")
continue
z .= x . "`r`n"
}
ifexist,%f1%
filedelete,%f1%
fileappend,%z%`r`n,%f1%,utf-8
;fileappend,%e4%`r`n,%f1%,utf-8
try
run,notepad "%f1%"
try
run,%f1%
z=
return
;----------------------
A1:
e4=
(Ltrim comments join`r`n `%
#warn
setworkingdir,%a_scriptdir%
e:=""
e .= "Line_01`r`n"
e .= "Line_02`r`n"
e .= "Line_03`r`n"
/*fff ggg hhh */
e .= "Line_04`r`n"
e .= "Line_05`r`n"
/*
comment
comment
comment
*/
e .= "Line_06`r`n"
e .= "Line_07`r`n"
/* comment
comment
comment */
e .= "Line_08`r`n"
e .= "Line_09`r`n"
e .= "Line_10`r`n"
aac=10 ;- this comment is removed from ltrim comments also the others ';'
;comment
e .= "Line_11`r`n"
e .= "Line_12`r`n"
; comment
e .= "Line_13`r`n"
e .= "Line_14`r`n"
msgbox, 262208,TEST,aac=%aac%`n%e%
e=
return
)
return
;=======================================================================