Meet npm Pro: unlimited public & private packages + package-based permissions.Learn more »


1.8.52 • Public • Published


Regular expression for matching HTML empty conditional comments

Minimum Node version required Repository is on GitLab Coverage no dependencies Downloads/Month Test in browser Code style: prettier MIT License

Table of Contents


npm i regex-empty-conditional-comments

The default is exported, so instead of "emptyCondCommentRegex" below, you can name the consumed function however you want.

Consume via a require():

const emptyCondCommentRegex = require("regex-empty-conditional-comments");

or as an ES Module:

import emptyCondCommentRegex from "regex-empty-conditional-comments";

or for web pages, as a production-ready minified script file (so-called "UMD build"), straight from CDN:

<script src=""></script>
// in which case you get a global variable "regexEmptyConditionalComments" which you consume like this:
const emptyCondCommentRegex = regexEmptyConditionalComments;

This package has three builds in dist/ folder:

Type Key in package.json Path Size
Main export - CommonJS version, transpiled to ES5, contains require and module.exports main dist/regex-empty-conditional-comments.cjs.js 407 B
ES module build that Webpack/Rollup understands. Untranspiled ES6 code with import/export. module dist/regex-empty-conditional-comments.esm.js 368 B
UMD build for browsers, transpiled, minified, containing iife's and has all dependencies baked-in browser dist/regex-empty-conditional-comments.umd.js 569 B

⬆ back to top


const emptyCondCommentRegex = require("regex-empty-conditional-comments");
// empty comment which was meant to target Outlook-only
emptyCondCommentRegex().t.test(`<!--[if !mso]>
//=> true
// empty comment which was meant to target non-Outlook-only
emptyCondCommentRegex().t.test(`<!--[if !mso]><!-- -->
//=> true
emptyCondCommentRegex().t.test(`<!--[if !mso]><!-- -->
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
//=> false
emptyCondCommentRegex().t.test(`<!--[if gte mso 9]><xml>
//=> false
emptyCondCommentRegex().exec("<html><!--[if !mso]><![endif]--><title>")[0];
//=> '<!--[if !mso]><![endif]-->'
`<html> <!--[if !mso]><![endif]--> <title>text</title> <!--[if gte mso 9]>
//=> ['<!--[if !mso]><![endif]-->']

⬆ back to top


  • If you see an error, raise an issue.
  • If you want a new feature but can't code it up yourself, also raise an issue. Let's discuss it.
  • If you tried to use this package, but something didn't work out, also raise an issue. We'll try to help.
  • If you want to contribute some code, fork the monorepo via GitLab, then write code, then file a pull request on GitLab. We'll merge it in and release.

In monorepo, npm libraries are located in packages/ folder. Inside, the source code is located either in src/ folder (normal npm library) or in the root, cli.js (if it's a command-line application).

The npm script "dev", the "dev": "rollup -c --dev" builds the development version retaining all console.logs with row numbers. It's handy to have js-row-num-cli installed globally so you can automatically update the row numbers on all console.logs.

⬆ back to top


MIT License

Copyright (c) 2015-2020 Roy Revelt and other contributors


npm i regex-empty-conditional-comments

DownloadsWeekly Downloads






Unpacked Size

14.1 kB

Total Files


Last publish


  • avatar