[code] bbcode外のhtmlタグをjavascriptで置き換え(削除)したいです。例えば:
<script>these</script> [code]<script>alert</script>[/code]<script>that</script>
なるべき
these [code]<script>alert</script>[/code]that
正規表現を使用して [コード] の外側のタグを置換/削除する方法は?
[code] bbcode外のhtmlタグをjavascriptで置き換え(削除)したいです。例えば:
<script>these</script> [code]<script>alert</script>[/code]<script>that</script>
なるべき
these [code]<script>alert</script>[/code]that
正規表現を使用して [コード] の外側のタグを置換/削除する方法は?
/(\[code\][\s\S]*?\[\/code\])|<[\s\S]*?>/g
これを$1
次のように置き換えます。
your_string.replace(/(\[code\][\s\S]*?\[\/code\])|<[\s\S]*?>/g, '$1');
最初にすべての[code]
タグを見つけて保存し、その後、残りの html タグ (タグには含まれません)を見つけ[code]
ます。
わかりました私は解決策を見つけます:
replace(/<(?=[^\[]*\[\/code\])/gi,"&_lt_;");
replace(/>(?=[^\[]*\[\/code\])/gi,"&_gt_;");
DO OTHER REPLACEMENT/CUSTOMIZATION HERE
replace(/&_lt_;/gi,"<");
replace(/&_gt_;/gi,">");
そのこと!:)