删除注释
我们讨厌没有注释,
我们常常承受着没有注释的痛苦,
但总有人要求我们把注释删掉.
正则: \/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$
替换: $1
正则: (\t+|\s+|\r\n)((/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|(//.*))
替换:
正则: [^:](\/\/.+)|(\/\*[\W\w\n\r]+?\*\/)
替换:
正则: (^[^"'`\n]+\/\/(.*))|(["'`]+.*["'`]+.*\/\/(.*))|(["'`]+.*["'`]+.*\/\*([\W\w\n\r]+?)\*\/)|(^[^"'`\n]+\/\*([\W\w\n\r]+?)\*\/)
替换:
正则: (/\\\*([^*]|[\\\r\\\n]|(\\\*+([^*/]|[\\\r\\\n])))*\\\*+/)|(//.*)
替换:
参考
- https://stackoverflow.com/questions/3885723/how-to-delete-all-comments-in-a-selected-code-section
- http://web.archive.org/web/20170909055410/http://blog.ostermiller.org/find-comment
- https://segmentfault.com/a/1190000015611632
- https://www.regextester.com/94245
- https://j11y.io/demos/comment-removal-js.html
- https://www.coder.work/article/3892831
- https://regex101.com/r/EwYpQl/1
- https://github.com/jonschlinkert/strip-comments
- https://github.com/vitaly-t/decomment
- https://github.com/aMarCruz/js-cleanup

浙公网安备 33010602011771号