Skip to content

Instantly share code, notes, and snippets.

@derhuerst
Created February 20, 2016 19:57
Show Gist options
  • Save derhuerst/494a71ee6e19732f312a to your computer and use it in GitHub Desktop.
Save derhuerst/494a71ee6e19732f312a to your computer and use it in GitHub Desktop.
comment regexes for a lot of languages

Taken from the wonderful sloc tool.

module.exports =
coffeescript: [/\#{3}/, /\#{3}/]
python: [/\"{3}|\'{3}/, /\"{3}|\'{3}/]
livescript: [/\/\*+/, /\*\/{1}/]
nix: [/\/\*+/, /\*\/{1}/]
ruby: [/\=begin/, /\=end/]
julia: [/\#\=/, /\=\#/]
javascript: [/\/\*+/, /\*\/{1}/]
typescript: [/\/\*+/, /\*\/{1}/]
c: [/\/\*+/, /\*\/{1}/]
'c++': [/\/\*+/, /\*\/{1}/]
'c#': [/\/\*+/, /\*\/{1}/]
haxe: [/\/\*+/, /\*\/{1}/]
arduino: [/\/\*+/, /\*\/{1}/]
java: [/\/\*+/, /\*\/{1}/]
php: [/\/\*+/, /\*\/{1}/]
go: [/\/\*+/, /\*\/{1}/]
groovy: [/\/\*+/, /\*\/{1}/]
css: [/\/\*+/, /\*\/{1}/]
scss: [/\/\*+/, /\*\/{1}/]
less: [/\/\*+/, /\*\/{1}/]
sass: [/\/\*+/, /\*\/{1}/]
stylus: [/\/\*+/, /\*\/{1}/]
rust: [/\/\*+/, /\*\/{1}/]
scala: [/\/\*+/, /\*\/{1}/]
lua: [/--\[{2}/, /--\]{2}/]
haskell: [/\{-/, /-\}/]
monkey: [/#rem/i, /#end/i]
racket: [/#\|/, /\|#/]
handlebars: [/\{\{\!/, /\}\}/]
mustache: [/\{\{\!/, /\}\}/]
html: [/<\!--/, /-->/]
svg: [/<\!--/, /-->/]
xml: [/<\!--/, /-->/]
ocaml: [/\(\*/, /\*\)/]
# from https://github.com/flosse/sloc/blob/0955d83e1127d68909b4bd98fd9ddd63f9a6b2a9/src/sloc.coffee#L100-L103
nimrod: [/\#{2}/]
module.exports =
coffeescript: /\#[^\{]/
crystal: /\#/
python: /\#/
livescript: /\#/
nix: /\#/
r: /\#/
ruby: /\#/
julia: /\#/
perl: /\#/
yaml: /\#/
# C-like
javascript: /\/\//
typescript: /\/\//
c: /\/\//
'c++': /\/\// # C++
'c#': /\/\// # C#
haxe: /\/\//
arduino: /\/\//
java: /\/\//
php: /\/\//
go: /\/\//
groovy: /\/\//
jade: /\/\//
css: /\/\//
scss: /\/\//
less: /\/\//
sass: /\/\//
stylus: /\/\//
rust: /\/\//
scala: /\/\//
swift: /\/\//
lua: /--/
haskell: /--/
erl: /\%/
monkey: /'/
'visual basic': /'/
# from https://github.com/flosse/sloc/blob/0955d83e1127d68909b4bd98fd9ddd63f9a6b2a9/src/sloc.coffee#L43-L57
nimrod: Object.assign /(?:^[^\#]*)(\#)(?:(?![\#\!]))/, _matchGroup_: 1
racket: /;/
clojure: /;/
hy: /;/
assembly: /;/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment