regex: java.util.regex companion code (groups, lookarounds, replaceAll lambdas, ReDoS and timeouts)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01KqJyCidz3ZgRyHABv2GVJh
This commit is contained in:
2026-09-30 19:00:39 +00:00
co-authored by Claude Sonnet 5.5
parent bfa7f97432
commit b31c6716a3
22 changed files with 647 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env bash
# Regenerates every file in ../output/. Requires JDK25_HOME.
set -euo pipefail
[[ -z "${JDK25_HOME:-}" ]] && { echo "JDK25_HOME must be set" >&2; exit 1; }
cd "$(dirname "$0")/.."
OUT=output; mkdir -p "$OUT"
export JAVA_HOME="$JDK25_HOME"
mvn -q -f ../pom.xml -pl regex -am package
J="$JDK25_HOME/bin/java"
run() { echo "==> $1"; "$J" -cp target/classes "com.ankurm.regex.$1" 2>&1 | grep -v "Picked up" > "$OUT/$2"; }
run BasicsDemo 01-basics.txt
run LookaroundDemo 02-lookarounds.txt
run ReplaceDemo 03-replace.txt
run BlowupDemo 04-blowup.txt
run FixesDemo 05-fixes.txt
run LimitsDemo 06-limits.txt
echo "==> JDK source: the backtracking mitigation and the absence of a timeout"
{
echo '$ java -version'; "$J" -version 2>&1 | grep -v "Picked up"
echo
echo '$ unzip -p lib/src.zip java.base/java/util/regex/Pattern.java | sed -n "/Optimize the greedy Loop/,/^ }$/p"'
unzip -p "$JDK25_HOME/lib/src.zip" java.base/java/util/regex/Pattern.java | sed -n '/Optimize the greedy Loop/,/^ }$/p'
echo
echo '$ grep -ci timeout Pattern.java Matcher.java'
for f in Pattern Matcher; do echo "$f.java: $(unzip -p "$JDK25_HOME/lib/src.zip" java.base/java/util/regex/$f.java | grep -ci timeout)"; done
} > "$OUT/07-jdk-source.txt"
cp target/surefire-reports/com.ankurm.regex.RegexClaimsTest.txt "$OUT/08-tests.txt"
echo Done