Regex for removing certain variable numeric values from some text

Posted by stephemurdoch on Stack Overflow See other posts from Stack Overflow or by stephemurdoch
Published on 2010-06-09T11:29:41Z Indexed on 2010/06/09 11:32 UTC
Read the original article Hit count: 280

Filed under:
|
|

I want to substitute all 4 instances of the number 300 from the code below, with 470.

<div>
  <object width="300" height="300">
    <embed src="link-removed" width="300" height="300"></embed>
  </object>
  <p>
    <a href="another-link">link</a>
  </p>
</div>

The width and height of the code being pasted might not always be 300 by 300.

So I figure I probably need a regular expression that subs any numeric value that follows the strings "width=" and "height=", whilst remembering to account for the quotations marks that surround the number. Can anyone tell me if that's the best way, and if so, what would be the best regex?

In case it matters, the code being pasted is stored as "text" in the db rather than as a string, as it's quite lengthy (i've removed a few hundred chars from what you see pasted here)...

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about regex