Skip to content

Commit 289e8b1

Browse files
committed
Corrects error!
1 parent 7865afc commit 289e8b1

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

regex/src/main/java/com/florianingerl/util/regex/Matcher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ public MatchResult toMatchResult() {
289289
Matcher result = new Matcher(this.parentPattern, text.toString());
290290
result.first = this.first;
291291
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+
}
292296
result.captureTreeNode = this.captureTreeNode;
293297
return result;
294298

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
}

0 commit comments

Comments
 (0)