返回提示词库Back to prompts
当前显示中英对照

开发编程coding

Regular Expressions taste

来自 prompts.chat 开放提示词库的公开模板,适合代码、调试和开发工作。正文保留原文,方便直接复制使用。

An open prompt template from prompts.chat for coding, debugging, and development. The original wording is preserved for direct copying.

ChatGPTClaudeGeminiCodex
0 次复制copies·小黑丸整理Curated by XHW

提示词正文Prompt text

复制后替换变量Replace variables after copying
# Regular Expressions taste of a developer who wants regexes people can still read
- Reach for a real parser for HTML, JSON, CSV, URLs and email headers; a regex is the wrong tool there. Confidence: 0.95
- Prefer plain string methods like `startsWith`, `includes` or `split` when they do the job. Confidence: 0.85
- Anchor patterns with `^` and `$` (or `\A` and `\z`) when validating a whole value. Confidence: 0.90
- Use named capture groups instead of counting numbered groups. Confidence: 0.85
- Use non-capturing groups `(?:...)` when you only need grouping, not the captured value. Confidence: 0.75
- Write long patterns in verbose mode with comments, such as `re.VERBOSE` in Python or the `x` flag where supported. Confidence: 0.80
- Prefer specific character classes like `[^"]*` over a lazy `.*?` to make intent clear and matching faster. Confidence: 0.80
- Avoid nested quantifiers like `(a+)+`; they invite catastrophic backtracking and ReDoS. Confidence: 0.95
- Never run user-supplied patterns without a timeout or a linear-time engine like RE2. Confidence: 0.90
- Put a length limit on input before matching it against any non-trivial pattern. Confidence: 0.85
- Compile patterns once at module level and reuse them instead of rebuilding them in a loop. Confidence: 0.75
- Escape dynamic text with `re.escape` or an equivalent helper before putting it into a pattern. Confidence: 0.95
- Turn on the Unicode flag (`u` or `v` in JavaScript) when the input may contain non-ASCII text. Confidence: 0.80
- Remember that `\d` and `\w` can match non-ASCII digits and letters in some engines; use `[0-9]` when you mean ASCII. Confidence: 0.70
- Keep each regex to one job; two simple patterns beat one clever pattern. Confidence: 0.80
- Give every important pattern a table-driven test with strings that must match and strings that must not. Confidence: 0.90
- Add a comment with a real example input above any pattern longer than about twenty characters. Confidence: 0.80
- Do not validate email addresses with a giant regex; check for one `@` and send a confirmation email. Confidence: 0.85
- Use lookarounds sparingly; if a pattern needs several of them, split the logic into code. Confidence: 0.70
- Try patterns in a tester like regex101 with the right engine selected before shipping them. Confidence: 0.70
# Regular Expressions taste of a developer who wants regexes people can still read
- Reach for a real parser for HTML, JSON, CSV, URLs and email headers; a regex is the wrong tool there. Confidence: 0.95
- Prefer plain string methods like `startsWith`, `includes` or `split` when they do the job. Confidence: 0.85
- Anchor patterns with `^` and `$` (or `\A` and `\z`) when validating a whole value. Confidence: 0.90
- Use named capture groups instead of counting numbered groups. Confidence: 0.85
- Use non-capturing groups `(?:...)` when you only need grouping, not the captured value. Confidence: 0.75
- Write long patterns in verbose mode with comments, such as `re.VERBOSE` in Python or the `x` flag where supported. Confidence: 0.80
- Prefer specific character classes like `[^"]*` over a lazy `.*?` to make intent clear and matching faster. Confidence: 0.80
- Avoid nested quantifiers like `(a+)+`; they invite catastrophic backtracking and ReDoS. Confidence: 0.95
- Never run user-supplied patterns without a timeout or a linear-time engine like RE2. Confidence: 0.90
- Put a length limit on input before matching it against any non-trivial pattern. Confidence: 0.85
- Compile patterns once at module level and reuse them instead of rebuilding them in a loop. Confidence: 0.75
- Escape dynamic text with `re.escape` or an equivalent helper before putting it into a pattern. Confidence: 0.95
- Turn on the Unicode flag (`u` or `v` in JavaScript) when the input may contain non-ASCII text. Confidence: 0.80
- Remember that `\d` and `\w` can match non-ASCII digits and letters in some engines; use `[0-9]` when you mean ASCII. Confidence: 0.70
- Keep each regex to one job; two simple patterns beat one clever pattern. Confidence: 0.80
- Give every important pattern a table-driven test with strings that must match and strings that must not. Confidence: 0.90
- Add a comment with a real example input above any pattern longer than about twenty characters. Confidence: 0.80
- Do not validate email addresses with a giant regex; check for one `@` and send a confirmation email. Confidence: 0.85
- Use lookarounds sparingly; if a pattern needs several of them, split the logic into code. Confidence: 0.70
- Try patterns in a tester like regex101 with the right engine selected before shipping them. Confidence: 0.70

使用场景Best used for

适合代码、调试和开发工作,使用前请替换其中的角色、主题和具体约束。

Useful for coding, debugging, and development. Replace the role, topic, and constraints before using it.

使用提醒Usage note

这条内容来自 prompts.chat 公开提示词库;说明为中英对照,正文保留来源原文。使用前请检查并按自己的工作场景改写。

Sourced from the prompts.chat public library. Descriptions are bilingual; the prompt preserves the original text. Review and adapt it to your work before use.