File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed
main/java/com/florianingerl/util/regex
test/java/com/florianingerl/util/regex/tests Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -289,6 +289,10 @@ public MatchResult toMatchResult() {
289
289
Matcher result = new Matcher (this .parentPattern , text .toString ());
290
290
result .first = this .first ;
291
291
result .last = this .last ;
292
+ result .groups = new int [this .groups .length ];
293
+ for (int i =0 ; i < this .groups .length ; ++i ) {
294
+ result .groups [i ] = this .groups [i ];
295
+ }
292
296
result .captureTreeNode = this .captureTreeNode ;
293
297
return result ;
294
298
Original file line number Diff line number Diff line change
1
+ package com .florianingerl .util .regex .tests ;
2
+
3
+ import static org .junit .Assert .assertEquals ;
4
+ import static org .junit .Assert .assertTrue ;
5
+
6
+
7
+ import org .junit .Test ;
8
+
9
+ import com .florianingerl .util .regex .Matcher ;
10
+ import com .florianingerl .util .regex .Pattern ;
11
+
12
+ public class ToMatchResultTest {
13
+
14
+
15
+ @ Test
16
+ public void testToMatchResult () {
17
+ Pattern pattern = Pattern .compile ("a(\\ w+)b" );
18
+ Matcher matcher = pattern .matcher ("ahellob" );
19
+ assertTrue ( matcher .find ());
20
+ assertEquals ("hello" , matcher .toMatchResult ().group (1 ));
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments