Statically collects global pattern matches such as ESM import declarations from code files.
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.
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:
fileContent (string): The raw file text to search.searchString (RegExp): A global (/g) regular expression pattern.Below is the code configuration and the corresponding matching results output:
import patternCollector from 'pattern-collector';
const matches = patternCollector({
fileContent: codeText,
searchString: /import\s+[\s\S]*?\s+from\s+['"][^'"]+['"]/g
});
[
"import { exec } from 'child_process'",
"import express from 'express'",
"import startServer from './server.js'"
]
Modify the code and regex below to see pattern results immediately.
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: