up vote 0 down vote favorite

Hi all,
Consider the following snippet of code:

<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>

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,
Amit

link|flag

10% accept rate

2 Answers

up vote 1 down vote

Yes.

var pt = string.match(/font-size:([\d.])+pt/)[1];

What do you want to do with that?

link|flag
up vote 0 down vote

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
link|flag

Your Answer

 
or
never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.