@bablr/regex-vm (英语)
@bablr/regex-vm 是一种全程的正则执行.
API 密码
测试(打印,输入)
执行(打印,输入)
执行全球(打印,输入)
input 预计将是流线的浏览器
测试
import { test } from '@bablr/regex-vm';
const didMatch = test(pattern, input);
didMatch 将会是 true 若为 pattern 某个位置的匹配 input。 。 。 .
执行
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 将是 [match, ...captures] 从第一个地点 pattern 匹配在 input。这个方法与其返回的光谱不同 [] (单位:千美元)没有 null当 pattern 未在 input,这样它就可以被更善地用于分解结构。 如果您需要检查匹配是否存在, 您仍然可以用解结构语法来做 :
const [match = null, $1] = exec(/.*(a)/, input);
if (match !== null) console.log(`match: '${match}'`);
if ($1 !== undefined) console.log(`$1: '${$1}'`);
执行全球
import { execGlobal } from '@bablr/regex-vm';
const [...matches] = execGlobal(pattern, input);
matches 是匹配数组的可移动性( x)StreamIterable[[match, ...captures], ...matches]) (中文(简体) ). 若为 pattern 未在 input 火柴将空出. execGlobal 与 global (单位:千美元)/g) 旗帜. 如果 /g 旗帜未显示 matches 可执行性永远不会包含一个以上的匹配.
图案和旗帜
一些语法是不支持的. 不支持的语法只要在支持良好的语法中仍然被解析 缩写 parser, 这样您将不会被允许写入无法与其他引擎兼容的表达式 .
-
图案使用"unicode模式"逃避规则. 只有有效的越狱在战术上是合法的.
-
模式不支持外观( E)
(?<=abc)财务报告和审定财务报表(?<!abc)) (中文(简体) ). -
模式不支持(也不会支持)回溯(
(.)\0) (中文(简体) ). -
模式不支持前置( 尚未) (
(?=abc)财务报告和审定财务报表(?!abc)) (中文(简体) ). 见 11号。 。 。 . -
模式不支持命名的捕获组( Q)
(?<name>)) (还. -
Unicode 旗帜(
/u)尚未支持。 支持它是一个最高优先事项。 见 33号。 。 。 . -
粘着的旗帜( Name
/y)部分支持. 它只限制匹配尝试pattern开始时input或在全球比赛结束时(何时)/g也在场)。 和放一个^在图案中,可能受多行旗影响(/m) (中文(简体) ).
贷项
谢谢杰森·普雷斯利! 没有你的 博客文章 我不知道从哪里开始。 也感谢我的朋友和家人,他们听到我谈论这件事比他们任何人都可能想要的要多.