Registry / serialization / regex-not

regex-not

JSON →
library1.0.2jsnpmunverified

regex-not, currently at version 1.0.2, is a utility package designed to simplify the creation of JavaScript regular expressions that match everything *except* a given string. It abstracts away the complexity of crafting negative lookahead assertions, which can be challenging and error-prone to write manually. The library is primarily a CommonJS module, targeted at Node.js environments from version 0.10.0 and above. Its release cadence is infrequent, suggesting a mature, stable API that is in a maintenance phase rather than active feature development. A key differentiator is its dual functionality: it can generate regexes for strict negation (the string does *not* exactly match) or 'contains' negation (the string does *not* contain the substring), providing flexibility for various inverse matching requirements.

npm install regex-not
INSTALL
IMPORT
SIG · REGEX-NOT
R
regex-not
serializationjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

not
const not = require('regex-not');
import not from 'regex-not';
The package is primarily CommonJS. For ESM, bundlers or a wrapper might be necessary. The default export is the `not` function.
not.create
const not = require('regex-not'); const regexString = not.create('foo');
import { create } from 'regex-not';
`.create` is a property on the default `not` function, not a separate named export. It returns the regex pattern string.

Demonstrates strict (default) and 'contains' negation using the `not` function, and how to get the raw regex pattern string using `not.create`.

const not = require('regex-not'); // Default behavior: matches if the string does NOT exactly equal 'foo' const reStrict = not('foo'); console.log('Strict matching:'); console.log(`'foo' should be false: ${reStrict.test('foo')}`); // Expected: false console.log(`'bar' should be true: ${reStrict.test('bar')}`); // Expected: true console.log(`'foobar' should be true: ${reStrict.test('foobar')}`); // Expected: true (not exact) // Option: matches if the string does NOT contain 'foo' const reContains = not('foo', { contains: true }); console.log('\nContains matching:'); console.log(`'foo' should be false: ${reContains.test('foo')}`); // Expected: false console.log(`'bar' should be true: ${reContains.test('bar')}`); // Expected: true console.log(`'foobar' should be false: ${reContains.test('foobar')}`); // Expected: false (contains 'foo') // Get just the regex pattern string const patternString = not.create('bar'); console.log(`\nGenerated pattern string for 'bar': ${patternString}`); const customRegExp = new RegExp(patternString); console.log(`Using custom RegExp: '${customRegExp.source}'.test('bar') should be false: ${customRegExp.test('bar')}`);
Debug
Known issues
gotchaThe package is primarily designed for CommonJS (CJS) environments and uses `require()`. Direct `import` statements in ES Modules (ESM) will likely fail without a bundler or specific Node.js configuration for CJS interoperability.
fix
Use `const not = require('regex-not');` in CJS files. For ESM, you might need to use `import not from 'regex-not';` but be aware that it relies on Node.js's CJS-ESM interoperability or a bundler's transpilation.
affects: >=1.0.0
gotchaBy default, `regex-not` generates a regex for *strict* negation, meaning it matches if the input string does NOT *exactly equal* the pattern. If you intend to match strings that do NOT *contain* a substring, you must explicitly set `options.contains: true`.
fix
For substring negation, call `not(string, { contains: true })`. For example, `not('foo', { contains: true })` will return a regex that doesn't match 'foobar'.
affects: >=1.0.0
gotchaThe package's low version (1.0.2) and infrequent updates indicate it's in maintenance mode. While stable for its current functionality, it may not receive updates for new JavaScript features, performance optimizations, or modern API patterns.
fix
Evaluate if the current functionality meets your needs without expecting future feature enhancements or major refactorings to adopt newer JS standards like native ESM.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to use `require()` in an ES Modules (ESM) context without a transpiler or specific Node.js configuration.
fix
If your project is ESM-first, try `import not from 'regex-not';` (though this package is CJS-primary, Node.js often handles this for default exports). Alternatively, convert your file to CommonJS if possible, or configure a bundler (like Webpack or Rollup) to handle CJS modules in an ESM project.
My regex doesn't work as expected; it matches strings that contain the pattern I want to exclude!
Misunderstanding the default 'strict' matching behavior of `regex-not`. By default, it excludes only exact matches, not partial containment.
fix
If you want the regex to match strings that *do not contain* a specific substring, you need to use the `contains` option: `not('your_pattern', { contains: true })`.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
regex-not — npm install regex-not · libregistry