
omdsh-dev/dsh-tool-regex
30Last commit Aug 14, 2026
dsh-tool-regex DSH plugin
This plugin provides four deterministic regex actions: test, find, replace, and explain. It runs in a worker thread with a 1-second timeout to prevent ReDoS attacks. All operations are purely functional with zero dependencies.
How to install the dsh-tool-regex DSH plugin
dsh plugin --profile web add github:omdsh-dev/dsh-tool-regexCopying does not run this command. Review the repository and version before installing the dsh-tool-regex DSH plugin.
dsh-tool-regex DSH plugin data source
dsh-tool-regex DSH plugin snapshot date: Aug 16, 2026
discovered
What the dsh-tool-regex DSH plugin can do
- test action: check if a pattern matches a given input (full match semantics expressed by model using ^...$).
- find action: extract all matches with index, full match, numbered captures, and named groups (auto-adds g flag if missing).
- replace action: global safe replacement using $1/$2/$<name>/$<unicode> with string replacement path (no eval).
- explain action: statically parse a regex pattern into a human-readable node sequence without executing it.
- ReDoS protection: worker hard timeout (1000ms), input size limits (64KB), pattern/replacement limits (16KB), and output limit (1MB).
Where the dsh-tool-regex DSH plugin fits
- Verifying user-provided regex patterns for correctness before use.
- Extracting fields from logs or text using named capture groups.
- Safe text replacement in AI-generated content without code execution.
- Understanding complex regex patterns via the explain action for debugging.
- Regex testing without spinning up a subprocess (bash/node/python) in a sandboxed environment.
Who the dsh-tool-regex DSH plugin is for
- AI model developers using DSH to add deterministic regex capabilities.
- Developers who need to validate and explain regex patterns statically in a sandboxed environment.
dsh-tool-regex DSH plugin limitations
- Only supports JavaScript regex syntax (without outer delimiters).
- Input text limited to 64KB, pattern to 16KB, replacement to 16KB; outputs over 1MB are rejected.
- find action results capped at 1,000 matches to prevent output bloat.
- explain action may fail for patterns exceeding 4,096 nodes (returns error).
- Not suitable for untrusted large inputs with nested quantifiers like (a+)+ or (.*)* (explicit warning in README).
dsh-tool-regex DSH plugin: from the repository README
Quoted from the omdsh-dev/dsh-tool-regex README, the upstream source of the dsh-tool-regex DSH plugin. Copyright remains with the original authors.
DSH 正则工具插件 —— 测试匹配、提取捕获组、安全替换、**静态解释正则含义(不执行任何代码)**。零依赖、纯函数。 [](LICENSE) ## 动机 模型经常需要验证用户给的 pattern、从日志/文本中提取字段、做文本替换。"心算"正则结果错误率极高,且无法给用户展示可验证的过程。现有替代是起 `bash` 进程跑 `node -e` 或 python——进程开销 + 模型现写脚本的正确性风险。内置 `grep` 只能做**文件域**搜索,无法对任意文本测试/提取/替换/解释。 本插件提供确定性正则工具,其中 `explain` 是差异化能力:静态解析 pattern 结构并给出人读解释,**不执行匹配**,天然免疫 ReDoS。 ## 安全模型(ReDoS 多层防线) JS 正则的灾难性回溯是真实威胁(如 `(a+)+$` 配合超长输入)。防线: 1. **worker 硬超时**:test/find/replace 在**可终止的 worker 线程**内同步执行,1,000ms 预算到期 `worker.terminate()` 并返回 `regex: execution timed out`——灾难性回溯不再能阻塞宿主进程(工具管道的 `timeoutMs` 对同步阻塞体是协作式,仅靠它不够;worker 内会再次执行全部上限校验) 2. **输入长度上限**:64,000 字节(UTF-8)——超限在入口直接拒绝,不进入回溯 3. **资源上限**:pattern ≤ 16KB、replacement ≤ 16KB、输出 ≤ 1MB、匹配数 ≤ 1,000(limit 钳制) 4. **explain 零执行**:只做静态 tokenizer,不构造 `RegExp` 实例,任何 pattern 都即时返回 > ⚠️ 工具描述与 README 均明确警告模型:**不要对不可信的大输入使用无锚点的嵌套量词 pattern**(如 `(a+)+`、`(.*)*`)。 其余边界:无效 pattern 捕获 `SyntaxError` 报错(含位置信息);无效/重复 flag 逐字符校验;`replace` 使用 `String.replace` **字符串替换路径**(JS 原生 `$`-语义,无 `new Function`、无 eval)。 ## 工具声明 注册 `regex` 工具(`@deepseek-ai/dsh-tool-regex`,row id `tool-regex`),统一输出 JSON 文本字符串。 | 参数 | 类型 | 必填 | 说明 | |---|---|---|---|
Read the full READMERepository license: MIT
dsh-tool-regex DSH plugin questions
How do I install the dsh-tool-regex plugin?
You can install it using the DSH CLI: `dsh plugin --profile web add github:omdsh-dev/dsh-tool-regex`. Alternatively, you can use `npm pack` to generate a tarball and install it with `dsh plugin --profile web add ./dsh-tool-regex-<version>.tgz`. Make sure to install for the correct profile (web or headless).
How do I test if a regex matches a string?
Use the `test` action: provide `pattern` (without slashes), `input` (the text to test), and optionally `flags`. The plugin returns `{"matched": true}` if the pattern matches, or `{"matched": false}` otherwise. For full-string matching, you should anchor the pattern with `^` and `$`.
How can I extract capture groups from a regex match?
Use the `find` action. The response includes an array of objects, each with `index`, `match`, `captures` (numbered groups), and `groups` (named groups). If the pattern doesn't have the `g` flag, the plugin automatically adds it to return all matches. Example: `regex { action: "find", pattern: "(\\w+)@(\\w+)", input: "a@b x c@d" }` returns two matches with captures.
How do I perform a safe regex replacement?
Use the `replace` action with `pattern`, `input`, `replacement`, and optionally `flags`. The replacement string supports `$1`, `$2`, `$<name>`, `$$` for literal `$`, etc. The plugin uses JavaScript's string replacement path, never `eval`. The response includes `result` and `replaced` count. Example: `regex { action: "replace", pattern: "(\\w+) (\\w+)", input: "hello world", replacement: "$2 $1" }` returns `{"result":"world hello","replaced":1}`.
Can I use the explain action to understand a regex pattern?
Yes. The `explain` action statically parses the pattern and returns a human-readable sequence of nodes. Each node has `kind`, `text`, and `meaning` fields. It does not execute the pattern, so it's safe even for ReDoS-vulnerable patterns. Example: `regex { action: "explain", pattern: "\\d{4}-\\d{2}" }` returns a list of nodes describing the pattern.