Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
haizhilin2013 opened this issue Aug 11, 2019 · 5 comments
Open
Labels
js JavaScript

Comments

@haizhilin2013
Copy link
Collaborator

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

@haizhilin2013 haizhilin2013 added the js JavaScript label Aug 11, 2019
@Clearives
Copy link

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

@nowherebutup
Copy link

nowherebutup commented Aug 12, 2019

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

@EmiyaYang
Copy link

EmiyaYang commented Aug 12, 2019

珠玉在前

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

@ywywZhou
Copy link

ywywZhou commented Nov 4, 2021

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

1 similar comment
@xiaoqiangz
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js JavaScript
Projects
None yet
Development

No branches or pull requests

6 participants