It doesn't add any new lines, rather it doesn't remove ones that already exist - it removes only the comment block, leaving everything else untouched. This means that
/* comment */ will get turned to
(four spaces), not an empty string. Similarly the surrounding newlines are not removed. This one also removes preceding whitespaces and following whitespaces/newlines:
RegExReplace(str, "\h*\/\*[\s\S]*?(\*\/\s*|$)")
But this means that
would be turned into
not
Whether this is desirable is up to you...
@mikeyww, learned something new today from you: AHK's regex symbol
. matches
\n and
\r but not
\n\r, so my
[\s\S] was actually not necessary. And also that forward-slashes don't need to be escaped... This meant that to make your Regex work in regex101.com I had to modify it to
\h*?\/\*[\s\S]*?(\*\/\s*|$).