简体   繁体   English

使用javascript修剪并返回特定字符集删除休息

[英]Trim and return specific character set removing rest using javascript

I need some help in returning value from the string below using javascript to use within google sheet.我需要一些帮助来使用 javascript 从下面的字符串返回值以在谷歌表中使用。

I need to return 0.3000 from the string below.我需要从下面的字符串中返回 0.3000。

Bid</span></td><td class="Ta(end) Fw(600) Lh(14px)" data-test="BID-value" data-reactid="51"><span class="Trsdu(0.3s) " data-reactid="52">0.3000</span>

I have tried the following but not getting desired results.我尝试了以下但没有得到想要的结果。 </span>/)[0].trim(); </span>/)[0].trim();

Please assist.请协助。

I'd suggest using String's match() to parse the input string.我建议使用 String 的match()来解析输入字符串。 Then you may use parseFloat() to make it a number.然后你可以使用parseFloat()使它成为一个数字。

 let input = 'Bid</span></td><td class="Ta(end) Fw(600) Lh(14px)" data-test="BID-value" data-reactid="51"><span class="Trsdu(0.3s) " data-reactid="52">0.3000</span>' let match = input.match(/>([\\d.]+)</) let output = match ? match[1] : undefined console.log(output, 'as string') console.log(parseFloat(output), 'as number')

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

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