FEATURE: String and Regular Expression Builtins
| Field | Value |
|---|---|
| Version | 20261028 V1 |
| Description | Manipulate strings and evaluate jq regular expression filters. |
| Depends On | FEATURE-CollectionBuiltins.md |
| Provides | jq string and regex builtins |
| Consumes | jq collection builtins |
Purpose
Provide the string and regular expression operations specified by the manual and exercised by the conformance corpus.
Behavior
Implement prefix and suffix tests and trimming, whitespace trimming, splitting and joining, indices and search, ASCII case conversion, and related string operations. Preserve Unicode codepoint indexing, embedded null characters, empty separators, stream-valued arguments, and jq error behavior.
Implement test, match, capture, scan, split, splits, sub, and gsub with the corpus-required regular expression syntax and flags. Match offsets and lengths count Unicode codepoints; unmatched captures have the specified null value and negative offset. Substitution evaluates its replacement filter against named captures and preserves multiple replacement results. Use only standard-library facilities while matching the required jq behavior.
Programmatic Acceptance
=== AC string-conformance ===
Intent: String searches, trimming, splitting, and joining execute their applicable corpus cases.
Suite: scoped
Requires: executable=python3; scope=test
Probe: --list
Probe Count: summary
import json import os import subprocess import sys
SELECT = r"^(?:split\(\"\"\)|indices\(1\)|indices\(\[1,2\]\)|indices\(\", \"\)|index\(\"!\"\)|ascii_upcase|trim, ltrim, rtrim|join\(\",\"\))$" result = subprocess.run( [sys.executable, "sources/run_conformance.py", "--select", SELECT, "--json"], capture_output=True, text=True, env={**os.environ, "JQ": os.path.abspath("jq")}, ) print(result.stdout) print(result.stderr, file=sys.stderr) report = json.loads(result.stdout) tally = report["summary"] assert sum(tally.values()) > 0, SELECT assert tally["fail"] == 0 and tally["error"] == 0, tally assert result.returncode == 0, result.returncode === END AC string-conformance ===
User Acceptance
- None.
Guardrails
- Do not mutate any file under
sources/. - Do not install packages or use a third-party jq implementation.
- Cross-feature cases requiring later builtins remain covered by scoped integration.