xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

html tag filter in js


const html = `可当天预订,必须21时15分之前下单,要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。</br>预订时间:最晚需在【出行当天21:15】前购买<br>有效期:选择的使用日期当天有效。<br>适用条件:身高:1米(含)以上<br>`;

// regex = /$<>^/ig;
// html.replace(regex, ``);

html.replace(/^<(.)*>$/ig, ``);
// "可当天预订,必须21时15分之前下单,要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。</br>预订时间:最晚需在【出行当天21:15】前购买<br>有效期:选择的使用日期当天有效。<br>适用条件:身高:1米(含)以上<br>"

html.replace(/^<.*>$/ig, ``);
// "可当天预订,必须21时15分之前下单,要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。</br>预订时间:最晚需在【出行当天21:15】前购买<br>有效期:选择的使用日期当天有效。<br>适用条件:身高:1米(含)以上<br>"

html.replace(/^<.*>$.*/ig, ``);
// "可当天预订,必须21时15分之前下单,要求必须<font color=green><b>60</b>分钟内完成</font>在线支付。</br>预订时间:最晚需在【出行当天21:15】前购买<br>有效期:选择的使用日期当天有效。<br>适用条件:身高:1米(含)以上<br>"

html.replace(/<[^>]+>/ig, ``);
// "可当天预订,必须21时15分之前下单,要求必须60分钟内完成在线支付。预订时间:最晚需在【出行当天21:15】前购买有效期:选择的使用日期当天有效。适用条件:身高:1米(含)以上"



https://regexper.com/#%2F<[^>]%2B>%2Fig

none of

/[^>]/ig

https://regexper.com/#%2F[^>]%2Fig

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

Regular Expressions Cheatsheet

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Cheatsheet

否定或补充字符集

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Groups_and_Ranges

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions/Assertions

strip html

https://ourcodeworld.com/articles/read/376/how-to-strip-html-from-a-string-extract-only-text-content-in-javascript

https://stackoverflow.com/questions/822452/strip-html-from-text-javascript

const stripHtml = (html = ``) => {
   let  tmp = document.createElement("div");
   tmp.innerHTML = html;
   return tmp.textContent || tmp.innerText || "";
}

regex

https://regexper.com/

RegExp

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp


https://www.npmjs.com/package/sanitize-html


taro html render bug

color 属性的引号没有 color="green" ???


原文地址:https://www.cnblogs.com/xgqfrms/p/12675991.html