@bablr/regex-vm

中文文档
1.0.4发布于 2026/05/25MITES Module近 30 天下载 4435

A fully streaming regular expression engine

原始使用文档
文档目录6 节
  1. API
  2. test
  3. exec
  4. execGlobal
  5. Patterns and flags
  6. Credits

@bablr/regex-vm

@bablr/regex-vm is a fully-featured streaming regex implementation.

API

test(pattern, input)
exec(pattern, input)
execGlobal(pattern, input)

input is expected to be a stream iterator

test

import { test } from '@bablr/regex-vm';

const didMatch = test(pattern, input);

didMatch will be true if pattern matches at some location in input.

exec

import { exec } from '@bablr/regex-vm';

const captures = exec(pattern, input);
// 1-indexed by lexical order of `(` ($2 is b)
const [match, $1, $2, $3] = exec(/(a(b))(c)/, input);

captures will be the array of [match, ...captures] from the first location where pattern matches in input. This method differs from the spec in that it returns [] (NOT null) when pattern is not found in input. This is so that it may be used more nicely with destructuring. If you need to check if the match was present, you can still do it nicely with destructuring syntax:

const [match = null, $1] = exec(/.*(a)/, input);

if (match !== null) console.log(`match: '${match}'`);
if ($1 !== undefined) console.log(`$1: '${$1}'`);

execGlobal

import { execGlobal } from '@bablr/regex-vm';

const [...matches] = execGlobal(pattern, input);

matches is an iterable of match arrays (StreamIterable[[match, ...captures], ...matches]). If pattern is not found in input the iterable of matches will be empty. execGlobal interacts with the global (/g) flag. If the /g flag is not present the matches iterable will never contain more than one match.

Patterns and flags

Some syntaxes are unsupported. Unsupported syntaxes are still parsed as long as they are in the well-supported regexpp parser, so that you will not be allowed to write expressions which would not be compatible with other engines.

  • Patterns use "unicode mode" escaping rules. Only valid escapes are syntactically legal.

  • Patterns do not support lookbehind ((?<=abc) and (?<!abc)).

  • Patterns do not (and will not) support backreferences ((.)\0).

  • Patterns do not support lookahead (yet) ((?=abc) and (?!abc)). See #11.

  • Patterns do not support named capture groups ((?<name>)) (yet).

  • The unicode flag (/u) is not supported yet. Supporting it is a top priority. See #33.

  • The sticky flag (/y) is partially supported. It restricts matching to only attempt to match pattern at the start of input or at the end of a global match (when /g is also present). Not the same as putting a ^ in the pattern, which may be affected by the multiline flag (/m).

Credits

Thanks Jason Priestley! Without your blog post I would not have known where to start. Also thanks to my friends and family, who have heard me talk about this more than any of them could possibly want to.

版本与发布记录

@bablr/regex-vm 共发布 25 个版本,首次发布于 2023/11/27;过去 12 个月发布了 8 个版本。

版本发布日期距今
1.0.4latest2026/05/255 个月前
1.0.32026/05/205 个月前
1.0.22026/05/205 个月前
1.0.12026/05/155 个月前
1.0.02026/05/145 个月前
0.14.22026/01/309 个月前

关于 @bablr/regex-vm 的常见问题

@bablr/regex-vm 是什么?

A fully streaming regular expression engine

如何安装 @bablr/regex-vm?

在项目目录运行 npm install @bablr/regex-vm,或使用 pnpm add / yarn add / bun add。

@bablr/regex-vm 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bablr__regex-vm 是否存在。

@bablr/regex-vm 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@bablr/regex-vm 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=12.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@bablr/regex-vm 可以商用吗?

@bablr/regex-vm 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bablr/regex-vm 的下载量有多少?

根据 npm 官方下载统计,@bablr/regex-vm 在 2026/10/08 – 2026/11/06 这 30 天内被下载 4,435 次,日均约 148 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bablr/regex-vm 还在维护吗?

最新版本 1.0.4 发布于 2026/05/25(5 个月前);至今共发布 25 个版本,其中过去 12 个月发布了 8 个;首次发布于 2023/11/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。