Fix lookaround regexes in String.lastIndexOf and replaceLast (#1908)

This commit is contained in:
Alexandre Kohler authored and GitHub committed 2026-10-13 11:32:12 -07:00
1 parent 88a50d167e
commit f4ad0da658
3 files changed
+5 -1

No files matched your search

@@ -1107,7 +1107,7 @@ public final class StringNodes {
} while (m.find());
// Reset `m` to the last match before returning (should always be `true` at this point)
return m.region(r.start(), r.end()).lookingAt();
return m.find(r.start());
}
/**
@@ -179,6 +179,7 @@ examples {
str3.lastIndexOf(Regex("ab"))
str3.lastIndexOf(Regex(""))
module.catch(() -> str3.lastIndexOf(Regex("b*c")))
str3.lastIndexOf(Regex("ab(?=y)"))
}
["lastIndexOfOrNull()"] {
@@ -230,6 +231,7 @@ examples {
str6.replaceLast(".", "x")
str6.replaceLast(Regex("."), "x")
module.catch(() -> str4.replaceLast(Regex("cc"), "$4; no such group"))
str3.replaceLast(Regex("(?<=x)ab"), "-")
}
["replaceAllMapped()"] {
@@ -144,6 +144,7 @@ examples {
6
9
"String does not contain a match for regex pattern. String : \"abxabyabz\" Pattern: Regex(\"b*c\")"
3
}
["lastIndexOfOrNull()"] {
6
@@ -184,6 +185,7 @@ examples {
"aabb.xaabbcc"
"aabb..aabbcx"
"Error replacing matches for regex `cc` with `$4; no such group`: `No group 4`"
"abx-yabz"
}
["replaceAllMapped()"] {
">>aa<<bbcc>>aa<<bbcc"