FAILURE MAP
← Case archive

FA-3901 / Regular expressions / Open access

Replacement counting reports matches instead of actual replacements · case 01

Replacement counting reports matches instead of actual replacements.

Verified by executionVariant 1 · 4 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

The implementation applies an operation whose text or grammar semantics violate this contract: Replace at most two digits with X and return [text,replacement_count].

VERIFIED REPAIR

Implement the complete stated contract, including the boundary fixtures: Replace at most two digits with X and return [text,replacement_count].

Unsuccessful approach: The attempted repair handles the primary example but still violates a separate boundary of the same contract.

Case contract

Replace at most two digits with X and return [text,replacement_count].

Why this case matters

A local executable model for consumers of structured text; oracle values are authored literals, not outputs copied from the repaired implementation.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return [re.sub(r'\d','X',x),len(re.findall(r'\d',x))]
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('123'), ['XX3', 2])
check('boundary 2', solve('a1'), ['aX', 1])
check('boundary 3', solve('none'), ['none', 0])
check('boundary 4', solve('12'), ['XX', 2])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 1['XXX', 3]['XX3', 2]Failed
boundary 2['aX', 1]['aX', 1]Passed
boundary 3['none', 0]['none', 0]Passed
boundary 4['XX', 2]['XX', 2]Passed

SHA-256 / 1fed33b2294bb9f489157d8e437675fe8edd751530cd0d6cea0795a7e2297117

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return [re.sub(r'\d','X',x,count=2),len(re.findall(r'\d',x))]
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('123'), ['XX3', 2])
check('boundary 2', solve('a1'), ['aX', 1])
check('boundary 3', solve('none'), ['none', 0])
check('boundary 4', solve('12'), ['XX', 2])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 1['XX3', 3]['XX3', 2]Failed
boundary 2['aX', 1]['aX', 1]Passed
boundary 3['none', 0]['none', 0]Passed
boundary 4['XX', 2]['XX', 2]Passed

SHA-256 / 0beb55f6ec703534d1d88359b18c0f6e2241d3f54cc6794f89fd1fe0ac1e6786

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import re, unicodedata, json, csv, io, html, base64, binascii, codecs, struct
from urllib.parse import quote, unquote, unquote_to_bytes, urlencode, parse_qsl, urlsplit, urlunsplit
from email.header import decode_header, make_header
from email.utils import getaddresses
from xml.etree import ElementTree as ET
import shlex, string, textwrap

N = 1
observations = []
def solve(x):
    try:
        return list(re.subn(r'\d','X',x,count=2))
    except Exception as exc:
        return {"error": type(exc).__name__}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('boundary 1', solve('123'), ['XX3', 2])
check('boundary 2', solve('a1'), ['aX', 1])
check('boundary 3', solve('none'), ['none', 0])
check('boundary 4', solve('12'), ['XX', 2])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
boundary 1['XX3', 2]['XX3', 2]Passed
boundary 2['aX', 1]['aX', 1]Passed
boundary 3['none', 0]['none', 0]Passed
boundary 4['XX', 2]['XX', 2]Passed

SHA-256 / c3e033234fac1098d0368587e90af7df8bdcbb37766fd4507117700064e0ff3d

Verification & scope

This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:37:32.432644+00:00.

Case digest / f8e5c23a1c7fa39b02dce964578b83b6106070d90a396c2a3d492814d35e9fd4