我遇到了这么一段字符串:
1 | <p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">vip范围</p><p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">上架起始时间</p><p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">上架道具ID</p><p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">下架时间</p><p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">充值时间</p> |
现在需要做的是把 tag
里面的 style
属性全部去掉变成这样 <p>...</p>
。
这里可以用的正则是 /\sstyle="[^"]*"/ig
。
1 | let str = `<p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">vip范围</p><p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">上架起始时间</p><p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">上架道具ID</p><p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">下架时间</p><p style="font-size: 12px; line-height: 12px; font-family: PingHei, Myriad Set Pro, Hiragino Sans GB, Microsoft Yahei, STHeiti, Helvetica, Arial, Verdana, sans-serif;">充值时间</p>`; |