In essence you can't do it with a regex without constraining yourself to the simpler cases. You need to parse a fair chunk of the language to be able to distinguish between comments and things that look like comments in other contexts, such as in strings as you have noted already. However dealing with nested comments is tough on regexen and is the real killer.
Note that the regex you give won't work as expected across multiple lines because . doesn't match newline characters unless you use the /s option.
In reply to Re: Regex to strip comments
by GrandFather
in thread Regex to strip comments
by zuma53
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |