Consider the following snippet of code:
<div align="Left">
<font style='font-size:17pt; font-family:Times New Roman;color:#000000;'&g开发者_StackOverflow中文版t;
<textformat tabstops="[20]" leftmargin="0">Hi all</textformat>
</font>
</div>
I want to extract string between "font-size" and "pt" i.e it should out me a decimal "17" using javascript.
Can this can be achieved using regular expression. Thanks in advance, AmitYes.
var pt = string.match(/font-size:([\d.])+pt/)[1];
What do you want to do with that?
In the case you just want to get the font size of the respective element I would recommend not relying on parsing the string but rather access this property by using the DOM – as for example something like:
document.getElementsByTagName('font')[0].style.fontSize
精彩评论