$string = <>;
$string =~
s{--\
[\
[([^\
]]|\
][^\
]])*--
[^\r\n
]*\
]\
]|
("(\\.|[^"\\
])*
"|'(\\.|[^'\\])*'|.[^-"'\\]*)}{defined $2 ? $2 : ""}gse; $string =~ s{--[^\n\r]*|(\[\[([^\]]|\][^\]])*\]\]|"(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.([^-\["'\\]|\[[^-\["'\\])*)}{defined $1 ? $1 : ""}gse;
$string =~ s{\s+|(\[\[([^\]]|\][^\]])*\]\]|"(\\.|[^"\\])*"|'(\\.|[^'\\])*'|.([^-\s\["'\\]|\[[^-\s\["'\\])*)}{defined $1 ? $1 : " "}gse;
$string =~ s{
\ ?([-+*\/%^={}().,;[\]])\ ? ## this matches every character lua doesn't care about wether a space is in front/behind of it. Example: "a = 5" equals "a=5".
| ## the part that makes quotes immume to the above match
( ## open the second catch
\[\[ ## an escape string opens
(
[^\]]|\][^\]] ## match until closure
)*
\]\] ## close
|
" ## an quote opens
(
\\. ## escaped char (to prevent closure on \")
|
[^"\\] ## not " or \
)*
" ## close
|
' ## an quote opens
(
\\. ## escaped char (to prevent closure on \")
|
[^'\\] ## not ' or \
)*
' ## close
|
. ## any char
([^-\ +*\/%^={}().,;[\]\["'\\]|\[[^-\ +*\/%^={}(),;[\]\["'\\])* ## none of the things that we want to match for
)
}{
}gxse;