使用javascript提取开始字符串和结束字符串之间的字符串
考虑以下代码片段:使用javascript提取开始字符串和结束字符串之间的字符串,javascript,Javascript,考虑以下代码片段: <div align="Left"> <font style='font-size:17pt; font-family:Times New Roman;color:#000000;'> <textformat tabstops="[20]" leftmargin="0">Hi all</textformat> </font> </div> 大家好 我想提取“font size”和“pt”之间的字符串
<div align="Left">
<font style='font-size:17pt; font-family:Times New Roman;color:#000000;'>
<textformat tabstops="[20]" leftmargin="0">Hi all</textformat>
</font>
</div>
大家好
我想提取“font size”和“pt”之间的字符串,也就是说,它应该使用javascript输出一个小数点“17”。这可以通过使用正则表达式来实现。
提前感谢,
阿米特是的
var pt = string.match(/font-size:([\d.])+pt/)[1];
您想用它做什么?如果您只想获得相应元素的字体大小,我建议您不要依赖于解析字符串,而是使用DOM访问此属性,例如:
document.getElementsByTagName('font')[0].style.fontSize