bra*_*r19 1 html javascript regex
例如我有这样的html:
\n\n<title>Ololo - text\xe2\x80\x99s life</title><div class="page-wrap"><div class="ng-scope"><div class="modal custom article ng-scope in" id="new-article" aria-hidden="false" style="display: block;"><div class="modal-dialog first-modal-wrapper">< div class="modal-content"><div class="modal-body full long"><div class="form-group">olololo<ul style="color: rgb(85, 85, 85);background-color: rgb(255, 255, 255);"><li>texttext</li><li>Filter the events lists by host.</li><li>Create graphs for separate hosts and for the groups of hosts.</li></ul><p style="color: rgb(85, 85, 85);background-color: rgb(255, 255, 255);">bbcvbcvbcvbcvbcvbcvbcvb</p></div></div></div></div></div></div><title>cvbcbcvbcvbcvbccb</title><div class="page-wrap"></div></div>\nRun Code Online (Sandbox Code Playgroud)\n\n我怎样才能从这样的html中删除所有样式类id等?
\n\n我有这样的正则表达式:
\n\n/<([a-z][a-z0-9]*)[^>]*?(\\/?)>/i\nRun Code Online (Sandbox Code Playgroud)\n\n怎么了?如何借助正则表达式删除所有html属性?
\n\n这是小提琴:
\n\n\n首先,我建议你在这种情况下不要使用正则表达式,它们并不意味着解析 HTML 等树形结构。
\n\n但是,如果您没有选择,我认为对于所请求的问题,您可以使用正则表达式。
\n\n在我看来,您好像忘记了空格、重音符号等。您可以利用不允许使用大于>和小于符号作为原始文本的事实。<
/<\\s*([a-z][a-z0-9]*)\\s.*?>/gi\nRun Code Online (Sandbox Code Playgroud)\n\n并用以下方式调用它:
\n\nresult = body.replace(regex, '<$1>')\nRun Code Online (Sandbox Code Playgroud)\n\n对于您给定的样本,它会产生:
\n\n<title>Ololo - text\xe2\x80\x99s life</title><div><div><div><div><div><div><div>olololo<ul><li>texttext</li><li>Filter the events lists by host.</li><li>Create graphs for separate hosts and for the groups of hosts.</li></ul><p>bbcvbcvbcvbcvbcvbcvbcvb</p></div></div></div></div></div></div><title>cvbcbcvbcvbcvbccb</title><div></div></div>\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
5780 次 |
| 最近记录: |