Сzsh
:
set -o extendedglob # for (#m) which in patterns causes the matched portion to be
# made available in $MATCH and the offset (1-based) in $MBEGIN
# (and causes the expansion of the replacement in
# ${var//pattern/replacement} to be deferred to the
# time of replacement)
haystack=aöæaæaæa
needle=æ
offsets=() i=0
: ${haystack//(#m)$needle/$((offsets[++i] = MBEGIN - 1))}
print -l $offsets