Match offsets
There are several ways to read offsets of your matched occurrences and your capturing groups.
Detail
#
Using If you use Detail
object (like the one passed to forEach()
or map()
callback) you can just use
offset()
method.
Method offset()
is UTF-8 safe and returns offsets in characters, not bytes.
For bytes, consider using byteOffset()
method. Use offset()
with multibyte-safe methods like mb_substr()
, and byteOffset()
with methods like substr()
.