{"id":16218,"library":"skip-regex","title":"skip-regex: Literal Regular Expression Detector","description":"skip-regex is a lightweight, zero-dependency JavaScript utility designed for the highly accurate and fast detection of literal regular expressions within a string. It is currently at version 1.0.2, with its last release in December 2018, indicating an abandoned or maintenance status rather than active development. The library provides a single function, `skipRegex(source: string, start: number)`, which identifies the end position of a regex given a starting slash. Its key differentiators include a minimal footprint, compatibility across NodeJS, various bundlers, and browsers (including IE9+), and comprehensive TypeScript definitions. This makes it suitable for parsing or code analysis tools that need to distinguish between division operators, comments, and regex literals reliably.","status":"abandoned","version":"1.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/aMarCruz/skip-regex","tags":["javascript","typescript","es6","micro","parser","detection","regex","regexp"],"install":[{"cmd":"npm install skip-regex","lang":"bash","label":"npm"},{"cmd":"yarn add skip-regex","lang":"bash","label":"yarn"},{"cmd":"pnpm add skip-regex","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the standard ESM import. For TypeScript, `esModuleInterop` should be enabled in `tsconfig.json` for this style.","symbol":"skipRegex","correct":"import skipRegex from 'skip-regex'"},{"note":"This is the CommonJS import pattern, suitable for Node.js or bundlers configured for CJS.","wrong":"import skipRegex from 'skip-regex' // without esModuleInterop in TypeScript","symbol":"skipRegex","correct":"const skipRegex = require('skip-regex')"},{"note":"This TypeScript-specific import syntax explicitly uses a `require`-style import, useful when `esModuleInterop` is not enabled.","wrong":"import { skipRegex } from 'skip-regex' // Incorrect for default export","symbol":"skipRegex","correct":"import skipRegex = require('skip-regex')"}],"quickstart":{"code":"import skipRegex from 'skip-regex'\n\nconst source = 'const foo = bar /.*/g; // this is a regex \\n const baz = 10 / 2; // division \\n const qux = /* comment */ 5;'\nlet start = 0;\nlet currentIndex = 0;\nlet detectedRegexes = [];\n\nwhile (currentIndex < source.length) {\n  start = source.indexOf('/', currentIndex);\n  if (start === -1) break;\n\n  const end = skipRegex(source, start);\n\n  if (end > start + 1) {\n    // Detected as regex if end is greater than start + 1 (meaning it found a regex beyond the initial slash)\n    const regex = source.slice(start, end);\n    detectedRegexes.push({ regex, start, end });\n    currentIndex = end;\n  } else {\n    // Not a regex, could be division or comment start.\n    // skipRegex returns start + 1 if it's not a regex, so we advance past the current slash.\n    currentIndex = start + 1;\n  }\n}\n\nconsole.log('Detected Regular Expressions:', detectedRegexes);\n// Example output shows how it distinguishes:\n// Detected Regular Expressions: [\n//   { regex: '/.*/g', start: 16, end: 22 }\n// ]","lang":"typescript","description":"This quickstart demonstrates how to iterate through a string to find and extract all literal regular expressions using `skipRegex`, differentiating them from division operators or comment starts."},"warnings":[{"fix":"Always ensure `source[start] === '/'` before calling `skipRegex(source, start)`. Use `source.indexOf('/')` to find valid starting points for a potential regex.","message":"The `start` parameter provided to `skipRegex` *must* point to a forward slash (`/`) character within the `source` string. If `start` points to any other character, the function's behavior is undefined or incorrect.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Enable `esModuleInterop: true` in your `tsconfig.json` or change the import statement to `import skipRegex = require('skip-regex')`.","cause":"Using `import skipRegex from 'skip-regex'` in a TypeScript project without `esModuleInterop` enabled in `tsconfig.json`.","error":"Module '\"skip-regex\"' has no default export. Did you mean to use 'import skipRegex = require(\"skip-regex\")'?"}],"ecosystem":"npm"}