diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java index 0450f2548..66f0a8ae2 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMatcher.java @@ -700,6 +700,7 @@ public final class TMatcher implements TMatchResult { this.rightBound = string.length(); matchResult = new TMatchResultImpl(cs, leftBound, rightBound, pat.groupCount(), pat.compCount(), pat.consCount()); + matchResult.useAnchoringBounds(true); } @Override diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineEOLSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineEOLSet.java index a3f163739..4efac26fe 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineEOLSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TMultiLineEOLSet.java @@ -52,7 +52,7 @@ class TMultiLineEOLSet extends TAbstractSet { @Override public int matches(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { int strDif = matchResult.hasAnchoringBounds() - ? matchResult.getLeftBound() - strIndex + ? matchResult.getRightBound() - strIndex : testString.length() - strIndex; char ch1; char ch2; diff --git a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSOLSet.java b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSOLSet.java index 2f6ee4df7..02400f1e9 100644 --- a/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSOLSet.java +++ b/classlib/src/main/java/org/teavm/classlib/java/util/regex/TSOLSet.java @@ -47,8 +47,7 @@ final class TSOLSet extends TAbstractSet { public int matches(int strIndex, CharSequence testString, TMatchResultImpl matchResult) { if (strIndex == 0 - || (matchResult.hasAnchoringBounds() && strIndex == matchResult - .getLeftBound())) { + || (matchResult.hasAnchoringBounds() && strIndex == matchResult.getLeftBound())) { return next.matches(strIndex, testString, matchResult); } return -1; diff --git a/tests/src/test/java/org/teavm/classlib/java/util/regex/MatcherTest.java b/tests/src/test/java/org/teavm/classlib/java/util/regex/MatcherTest.java index 69f15167b..afa9c9f76 100644 --- a/tests/src/test/java/org/teavm/classlib/java/util/regex/MatcherTest.java +++ b/tests/src/test/java/org/teavm/classlib/java/util/regex/MatcherTest.java @@ -726,6 +726,15 @@ public class MatcherTest { assertTrue("The result doesn't contain pattern info", result.contains("(\\d{1,3})")); } + @Test + public void testSOLRegion() { + Pattern pattern = Pattern.compile("^cd"); + String input = "abcde"; + Matcher matcher = pattern.matcher(input); + matcher.region(2, input.length()); + assertTrue(matcher.lookingAt()); + } + private void hitEndTest(boolean callFind, String testNo, String regex, String input, boolean hit) { Pattern pattern = Pattern.compile(regex);