詳細情報ありがとうございます。状況がよくわかりました。
全角文字だけ数値文字参照
最初にstyle/scriptタグがどこにあるかを調べてから、必要な範囲だけを切り出して作業。とかどうでしょう。
#include "mod_regexp.as"
a={"
<HTML>
<head>
<TITLE>こんにちは。</TITLE>
<style>
body{
font-family: "MS ゴシック",MS GOSIC
}
</style>
</head>
<body>
<script>
alert("あ");
</script>
あいうえお
</body>
</HTML>
"}
;gr_2byte = "[^!-~\r\n\t ]" ; 2バイト文字
;gr_tags = "<[^<>/]+>" ; 開始タグ
;gr_tage = "</[^<>]+>" ; 終了タグ
gr_styles = "<style[^<>/]*>" ; style 開始タグ
gr_stylee = "</style>" ; style 終了タグ
;gr_scripts = "<script[^<>/]*>" ; script 開始タグ
;gr_scripte = "</script>" ; script 終了タグ
;styleタグの位置を調べる
matches s, a, gr_styles, 0, 0, 0
matches e, a, gr_stylee, 0, 0, 0
sidx = instr(a, idx, s(cnt))
eidx = instr(a, idx, e(cnt))
mes "---"
idx = 0
mes strmid(a, idx, sidx)
mes "---"
idx = eidx + strlen(e(0))
mes strmid(a, idx, strlen(a))
あるいは、styleタグやscriptタグは必ず中では{〜}で囲まれているので、{〜} と 全角文字 だけを抽出して作業とか…。
gr = "{[^{}]*}|[^!-~\r\n\t ]+" ; {〜} または 全角文字
matches b, a, gr, 0, 0, 1
repeat stat
mes "全角:"+b(cnt)
loop
> 変数cnt番目の文字を一文字切り出す。
これならあらやさんのやり方が実装しやすいかもしれませんね。
1文字ずつ処理は、昔個人的にとても大変だった(でもちゃんと作った)思い出があるので、つい正規表現で一括処理とかをおすすめしてしまいます。