JavaScript String Replace with a tricky regular expression
Posted
by Juri
on Stack Overflow
See other posts from Stack Overflow
or by Juri
Published on 2010-03-22T17:23:59Z
Indexed on
2010/03/22
17:51 UTC
Read the original article
Hit count: 410
Hi.
I'm trying to work out what regular expression I would need to change this string
html = '<img style="width: 311px; height: 376px;" alt="test" src="/img/1268749322.jpg" />';
to this
html = '<img width="311" height="376" alt="test" src="/img/1268749322.jpg" />';
with the help of Javascript.replace.
This is my start:
html = html.replace(/ style="width:\?([0-9])px*"/g, "width=\"$1\"");
Can anyone help me?
THANKS
© Stack Overflow or respective owner