Skip to content

Commit 5df0f99

Browse files
committed
docs(core): clarify limitations of anonymous capturing groups in SiftPatterns
- Updated Javadoc for SiftPatterns.capture(SiftPattern) to explicitly state that anonymous groups bypass internal tracking, collision detection, and cannot be used with DSL backreferences. - Directed developers to use NamedCapture if strict safety and DSL backreferencing are required.
1 parent 1551305 commit 5df0f99

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

sift-core/src/main/java/com/mirkoddd/sift/core/SiftPatterns.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,16 @@ public static SiftPattern anyOf(java.util.List<? extends SiftPattern> patterns)
103103
}
104104

105105
/**
106-
* Wraps a pattern in a <b>Capturing Group</b> {@code (...)}.
106+
* Wraps a pattern in an <b>Anonymous Capturing Group</b> {@code (...)}.
107107
* <p>
108108
* Capturing groups allow you to extract specific parts of the matched string
109-
* using {@code Matcher.group(int)}.
109+
* using the standard Java {@code Matcher.group(int)} after evaluation.
110+
* <p>
111+
* <b>Limitation Note:</b> Because this creates an anonymous (numbered) group,
112+
* it is <b>not</b> tracked by Sift's internal group registry. This means you cannot
113+
* reference it using Sift's DSL backreference methods, and it bypasses group collision detection.
114+
* If you need to use backreferences within your Sift builder chain, or want strict
115+
* collision safety, use {@link #capture(String, SiftPattern)} to create a {@link NamedCapture} instead.
110116
*
111117
* @param pattern The pattern to capture.
112118
* @return A SiftPattern wrapped in parentheses.

0 commit comments

Comments
 (0)