V2 Story: Regex Collector

Statically collects global pattern matches such as ESM import declarations from code files.

🧩 Regex Collector 🔎 Global Matches 🔥 Raw Engine

1. What

The Regex Collector Story (V2) is designed to scan file content and capture every substring matching a custom global regular expression. It does not perform structural evaluations or cross-referencing between statements, serving as the foundational raw pattern scanning engine.

2. How

The analyzer receives the raw code text and a global RegExp pattern. It repeatedly executes the regular expression against the code content in a loop, gathering all occurrences in order and outputting them as an array of matching text segments.

Key Parameters:

3. Example

Below is the code configuration and the corresponding matching results output:

JavaScript Execution

import patternCollector from 'pattern-collector';

const matches = patternCollector({
  fileContent: codeText,
  searchString: /import\s+[\s\S]*?\s+from\s+['"][^'"]+['"]/g
});

Output Results

[
  "import { exec } from 'child_process'",
  "import express from 'express'",
  "import startServer from './server.js'"
]

🎮 Live Playground

Modify the code and regex below to see pattern results immediately.

Matches Result
Click "Collect Patterns" to see results.

4. Dependency Diagram

The dependency tree highlights how this story calls the custom packages in the ecosystem, utilizing the raw scanning logic of the base pattern-collector library:

graph TD user_code["regex-collector.html (V2 Story)"] --> pc_anyjs["pattern-collector-anyjs"] pc_anyjs --> pc["pattern-collector"] style user_code fill:#1e293b,stroke:#38bdf8,stroke-width:2px,color:#f8fafc style pc fill:#020617,stroke:#818cf8,stroke-width:1px,color:#cbd5e1 classDef default fill:#0f172a,stroke:#334155,color:#f8fafc;