agentleFS
narenaryannarenaryan/agent-skills/skills/rust/rust-regex-search-contracts/SKILL.md

rust-regex-search-contracts

Skill0 starsChanged 39 days agoMITView on GitHub

Use when Rust regex refactors change match offsets, sliced searches invent word boundaries, a lexer skips invalid input, or multi-pattern searches choose the wrong token after switching engines.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Search configuration is part of correctness.

    line 8
  2. Distinctive:

    Prefer the meta engine unless measured requirements justify owning lower-level limitations.

    line 20
  3. Distinctive:

    Before replacing an engine, compare pattern IDs, spans, captures, empty matches, Unicode cases, and errors, not just match counts.

    line 40

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Rust Regex Search Contracts

Search configuration is part of correctness. A faster engine is interchangeable only when its match policy, boundary context, offsets, and failure behavior match the caller's contract.

Choose the contract first

NeedConstructTrap
Boolean existencemeta::Regex::is_matchComputing captures adds unnecessary work
Search a regionInput::new(full).span(start..end)Slicing changes boundary context and rebases offsets
Match at a lexer cursor.anchored(Anchored::Yes)Unanchored search silently skips unmatched bytes
Token identity plus spanmeta::Regex::new_manyPattern order breaks equal-start ties; this is not longest-token selection
Specialized engineFallible search plus explicit fallbackMatchError is indeterminate, not “no match”

Prefer the meta engine unless measured requirements justify owning lower-level limitations. It composes engines and fallbacks; choosing a standalone DFA also transfers unsupported-input handling to you.

Preserve context

With regex-automata = "=0.4.13":

use regex_automata::{meta::Regex, Anchored, Input};
let re = Regex::new(r"\bcat\b")?;
let hay = "bobcat!";
assert!(re.is_match(&hay[3..6])); // Wrong context: invents a word.
assert!(!re.is_match(Input::new(hay).span(3..6)));

let token = Regex::new(r"[a-z]+")?;
let input = Input::new("!cat").span(0..4).anchored(Anchored::Yes);
assert!(token.find(input).is_none()); // Reject the gap; don't skip '!'.

Anchored::Yes refers to the search start. Default ^ refers to the haystack start; multiline mode changes its meaning again. Validate input ranges before searching. Keep returned offsets in the original byte coordinate system.

Before replacing an engine, compare pattern IDs, spans, captures, empty matches, Unicode cases, and errors, not just match counts. The fixture provides six failure/remedy cases; provenance records runtime limits.

Pitfalls

  • Reordering alternatives or patterns changes leftmost-first results. Longest-token lexing needs its own explicit selection policy.
  • earliest(true) may change the chosen match; it is not a semantics-preserving speed switch.
  • MatchKind::All is not a drop-in “find every occurrence” mode for ordinary unanchored iteration.
  • Handwritten cursor loops can stall on empty matches; use the engine's iterator when its non-overlapping semantics fit.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.