{"id":15226,"library":"regex-not","title":"Negative Regular Expression Generator","description":"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.","status":"maintenance","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/jonschlinkert/regex-not","tags":["javascript","exec","match","negate","negation","not","regex","regular expression","test"],"install":[{"cmd":"npm install regex-not","lang":"bash","label":"npm"},{"cmd":"yarn add regex-not","lang":"bash","label":"yarn"},{"cmd":"pnpm add regex-not","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is primarily CommonJS. For ESM, bundlers or a wrapper might be necessary. The default export is the `not` function.","wrong":"import not from 'regex-not';","symbol":"not","correct":"const not = require('regex-not');"},{"note":"`.create` is a property on the default `not` function, not a separate named export. It returns the regex pattern string.","wrong":"import { create } from 'regex-not';","symbol":"not.create","correct":"const not = require('regex-not');\nconst regexString = not.create('foo');"}],"quickstart":{"code":"const not = require('regex-not');\n\n// Default behavior: matches if the string does NOT exactly equal 'foo'\nconst reStrict = not('foo');\nconsole.log('Strict matching:');\nconsole.log(`'foo' should be false: ${reStrict.test('foo')}`);     // Expected: false\nconsole.log(`'bar' should be true: ${reStrict.test('bar')}`);     // Expected: true\nconsole.log(`'foobar' should be true: ${reStrict.test('foobar')}`); // Expected: true (not exact)\n\n// Option: matches if the string does NOT contain 'foo'\nconst reContains = not('foo', { contains: true });\nconsole.log('\\nContains matching:');\nconsole.log(`'foo' should be false: ${reContains.test('foo')}`);     // Expected: false\nconsole.log(`'bar' should be true: ${reContains.test('bar')}`);     // Expected: true\nconsole.log(`'foobar' should be false: ${reContains.test('foobar')}`); // Expected: false (contains 'foo')\n\n// Get just the regex pattern string\nconst patternString = not.create('bar');\nconsole.log(`\\nGenerated pattern string for 'bar': ${patternString}`);\nconst customRegExp = new RegExp(patternString);\nconsole.log(`Using custom RegExp: '${customRegExp.source}'.test('bar') should be false: ${customRegExp.test('bar')}`);","lang":"javascript","description":"Demonstrates strict (default) and 'contains' negation using the `not` function, and how to get the raw regex pattern string using `not.create`."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For substring negation, call `not(string, { contains: true })`. For example, `not('foo', { contains: true })` will return a regex that doesn't match 'foobar'.","message":"By 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`.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `require()` in an ES Modules (ESM) context without a transpiler or specific Node.js configuration.","error":"ReferenceError: require is not defined"},{"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 })`.","cause":"Misunderstanding the default 'strict' matching behavior of `regex-not`. By default, it excludes only exact matches, not partial containment.","error":"My regex doesn't work as expected; it matches strings that contain the pattern I want to exclude!"}],"ecosystem":"npm"}