【发布时间】:2015-05-10 16:21:21
【问题描述】:
例如我有这样的html:
<title>Ololo - text’s 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>
如何从此类 html 中删除所有样式类 ID 等?
我有这样的正则表达式:
/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i
怎么了?如何借助正则表达式删除所有html属性?
这里是小提琴:
【问题讨论】:
-
Don't try to parse HTML with regexs。 (除非非常有限,已知html)
-
@JamesThorpe 没有别的办法(((
-
@jamesthorpe 说的是对的。如果您想这样做,请编辑您的 html 或 - 在最坏的情况下,如果您必须 - 使用 javascript 删除每个...
-
总有另一种方式=D
-
@bwegs 属性不是标签
标签: javascript html regex