私は、ユーザーがコピーしてフォームに貼り付けるコードを変更する機能を必要とする従来の ASP アプリケーションで作業しています。ユーザーは、html に精通していない信頼できるユーザーと見なされます。
width=""
ユーザーが提供されたコードのすべての属性を変更したい場合、テキストボックスラベルの幅に正しい値を入力して保存/送信を押すだけでよいようにしようとしています。次に、スクリプトはすべての幅属性を検索し、提供された html スニペットでそれらの値を更新します。
私はこれを行うための正規表現に取り組んできましたが、調査中に、多くの人がこの種のことに対して正規表現を推奨せず、何らかの html パーサー オブジェクトを使用したいと考えていることを読みました。
従来の ASP で利用できる html パーサーまたは DOM ブラウザー/エディターはありますか? それとも正規表現の開発を続ける必要がありますか?
正規表現の場合、これは私がこれまでに持っているものです...最初のものだけでなく、すべての一致で置換を実行するように変更する必要があります:
function replaceBetween(sSource, sStart, sStop, sValue)
thisNewValue = sStart & sValue & sStop
set re = new regexp
re.pattern = "(" & "" &sStart & ")(.*?)(" & sStop & ")"
re.IgnoreCase = true
response.write "Pattern: <b>" & re.pattern & "</b><br />" & vbnewline
response.write "thisNewValue: <b>" & thisNewValue & "</b><br />" & vbnewline
response.write "match: <b>" & re.test(sSource) & "</b><br />" & vbnewline
replaceBetween = re.replace(sSource, thisNewValue)
end function
sourceText = ("<div class='thisclass' id=""thisID""><a anotherthing="""" attribute=""one""><a attribute=""2""><a anotherattribute="" attribute=""three 3""></div>")
replacestart = "attribute="""
replacestop = """"
newvalue = "XXXX"
response.write "updated source: <b>" & server.HTMLEncode(replaceBetween(sourceText,replacestart,replacestop,newvalue)) & "</b><br />" & vbnewline