Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
86 views
in Technique[技术] by (71.8m points)

javascript - 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 "?"

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(/
/g, "")

Any help would be appreciated thanks!

question from:https://stackoverflow.com/questions/65849212/how-to-remove-symbol-from-string-using-replace

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Why not work with substr?

let text = document 
  .querySelector('.tracktime')
  .textContent
  .trim()
  .substr(0, 5);

console.log(text);
<span class="tracktime">06:21
- 15.26 mb</span>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...