Skip to content

[js] 第118天 使用正则去掉html中标签与标签之间的空格 #1055

Open
@haizhilin2013

Description

@haizhilin2013
Collaborator

第118天 使用正则去掉html中标签与标签之间的空格

Activity

Clearives

Clearives commented on Aug 12, 2019

@Clearives
htmlStr.replace(/>\s+</g, '><')
nowherebutup

nowherebutup commented on Aug 12, 2019

@nowherebutup
  const html = `
  <div>
    <span class="cls" id="spa">111</span>
    <span>222</span>
  </div>`;
  String.prototype._trim = function () {
    return this.replace(/>[\s]+</g, '><')
  }
EmiyaYang

EmiyaYang commented on Aug 12, 2019

@EmiyaYang

珠玉在前

const html = `
<div>
   <span>      我两边怎么有空格?  </span>
</div>
`
console.log(html.replace(/>\s*(\S*)\s*</g, ">$1<"));
ywywZhou

ywywZhou commented on Nov 4, 2021

@ywywZhou

htmlStr.replace(/>\s+</g, '><')

xiaoqiangz

xiaoqiangz commented on Jul 7, 2022

@xiaoqiangz

htmlStr.replace(/>\s+</g, '><')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    jsJavaScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haizhilin2013@Clearives@xiaoqiangz@EmiyaYang@nowherebutup

        Issue actions

          [js] 第118天 使用正则去掉html中标签与标签之间的空格 · Issue #1055 · haizlin/fe-interview