360 Secure SkillHub
360 安全技能中心

regex-builder

面向需要匹配、提取、校验或替换文本的用户:先澄清正反例与目标正则方言,再写出可读的正则并逐 token 解释,最后给出 Python 或 Node 运行片段验证正反例,并提示贪婪匹配、回溯等常见陷阱。

widoxm
widoxm
热度 42.17
最近更新 2026-08-31 20:36:43
分类:开发依赖:内部调用大模型 / 代码执行应用场景:代码生成 / 概念解释 / 调试排错

安装技能

复制下面的话术发给你的 Agent,它会通过 secure-skills 检索并安装该技能。

执行命令安装此 skill: npx secure-skills-cli add widoxm/regex-builder
Metadata
name
regex-builder
description
Write, explain, and test regular expressions. Use when the user needs to match, extract, validate, or replace text with a pattern, or asks what a regex does.

Regex Builder

Help the user write correct, readable regular expressions and understand the ones they already have.

Workflow

  1. Clarify intent. Before writing anything, pin down:

    • 2–3 positive examples that must match.
    • 2–3 negative examples that must NOT match.
    • The regex dialect (JavaScript, Python, PCRE, POSIX, etc.).
  2. Write it. Favor readability over cleverness:

    • Prefer explicit character classes over a broad . when the input is known.
    • Use a non-capturing group (?:...) unless a capture is actually consumed later.
    • Anchor with ^ / $ when the whole string must match.
  3. Explain it. For an existing regex, break it down token by token in plain language.

  4. Test it. Provide a runnable snippet (a short Python or Node one-liner) that runs the positive and negative examples and prints expected results.

Pitfalls to catch

  • Unescaped metacharacters inside character classes.
  • Greedy quantifiers matching too much — prefer .*? or a negated class.
  • Forgetting that . does not match newlines in most engines.
  • Catastrophic backtracking from nested quantifiers such as (a+)+.