diff --git a/crates/typst/src/eval/str.rs b/crates/typst/src/eval/str.rs index b21d2ff9d..140f71465 100644 --- a/crates/typst/src/eval/str.rs +++ b/crates/typst/src/eval/str.rs @@ -116,7 +116,22 @@ impl Str { match pattern { StrPattern::Str(pat) => self.0.ends_with(pat.as_str()), StrPattern::Regex(re) => { - re.find_iter(self).last().map_or(false, |m| m.end() == self.0.len()) + let mut start_byte = 0; + while let Some(mat) = re.find_at(self, start_byte) { + if mat.end() == self.0.len() { + return true; + } + + // There might still be a match overlapping this one, so + // restart at the next code point + if let Some(c) = &self[mat.start()..].chars().next() { + start_byte = mat.start() + c.len_utf8(); + } else { + break; + } + } + + false } } }