Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

comment-regex

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

comment-regex

Regular expression for matching JavaScript comments

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12K
decreased by-8.1%
Maintainers
1
Weekly downloads
 
Created
Source

comment-regex

Regular expression for matching JavaScript comments

This is pretty fragile and created for performance reasons where using a real parser would be overkill. Do not use it with untrusted user input.

Install

npm install comment-regex

Usage

import {commentRegex} from '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.

lineCommentRegex()

Returns a regex for matching line comments.

blockCommentRegex()

Returns a regex for matching block comments.

Keywords

FAQs

Package last updated on 13 Oct 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc