简体   繁体   English

如何使用.replace从字符串中删除↵符号

[英]How to remove ↵ symbol from string using .replace

I have data that I am trying to scrape and save to JSON but I'm getting this symbol "↵"我有数据要尝试抓取并保存到 JSON 但我得到了这个符号“↵”

For example my data is this -例如我的数据是这样的 -

<span class="tracktime">06:21
- 15.26 mb</span>

I am trying to save the duration only using -我正在尝试仅使用-保存持续时间-

'duration': $(this).find('span[class="tracktime"]').text().trim().replace(/\↵/g, " ").trim().split(" ")[0]

but the data I am getting back is -但我得到的数据是 -

duration: "06:21↵-"

I have also tried this with no luck -我也试过这个没有运气 -

.replace(/\r\n/g, "")

Any help would be appreciated thanks!任何帮助将不胜感激谢谢!

Why not work with substr ?为什么不使用substr

 let text = document.querySelector('.tracktime').textContent.trim().substr(0, 5); console.log(text);
 <span class="tracktime">06:21 - 15.26 mb</span>

If all you want to achieve is replacing the new line, go like this:如果您想要实现的只是更换新线 go ,如下所示:

 let text = document.querySelector('.tracktime').textContent.trim().replaceAll('\n', ''); console.log(text);
 <span class="tracktime">06:21 - 15.26 mb</span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM