JSPM

comment-regex

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 18982
  • Score
    100M100P100Q136555F
  • License MIT

Regular expression for matching JavaScript comments

Package Exports

  • comment-regex

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (comment-regex) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

comment-regex Build Status

Regular expression for matching JavaScript comments

This is pretty fragile and created for perf reasons where a using real parser would be overkill.

Install

$ npm install --save comment-regex

Usage

var commentRegex = require('comment-regex');

// contains a comment
commentRegex().test('/* unicorn */\nvar foo = true;');
//=> true

// get the contents of a comment
commentRegex().exec('/* unicorn */\nvar foo = true;')[2].trim();

// get all the comments
'/* unicorn */\nvar foo = true;\nvar unicorn = "rainbows"; // rainbow'.match(commentRegex());
//=> ['/* unicorn */', ' // rainbow']

API

The contents of the comment is in the first submatch.

commentRegex()

Returns a regex for matching line and block comments.

commentRegex.line()

Returns a regex for matching line comments.

commentRegex.block()

Returns a regex for matching block comments.

License

MIT © Sindre Sorhus