[[ Bug 13762 ]] Changed begins with / ends with to ensure it works with grapheme boundaries.
[[ Bug 13762 ]] Factored out grapheme boundary check.