开发者

Extract string between start string and end string using javascript

开发者 https://www.devze.com 2023-01-14 00:28 出处:网络
Consider the following snippet of code: <div align=\"Left\"> <font style=\'font-size:17pt; font-family:Times New Roman;color:#000000;\'&g开发者_StackOverflow中文版t;

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,

Amit


Yes.

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
0

精彩评论

暂无评论...
验证码 换一张
取 消