The following examples take into account the ordering, what quotations are used, and if people put in spaces
A straight replace:
embeddedString = embeddedString.replace(/(width\s*=\s*["'])[0-9]+(["'])/ig, $1 + yourWidth + $2);
embeddedString = embeddedString.replace(/(height\s*=\s*["'])[0-9]+(["'])/ig, $1 + yourHeight + $2);
Or to transform the width:
embeddedString = embeddedString.replace(/width\s*=\s*["']["']/ig, function($0, $1)
{
return $1 * 2;
});
if you actually want to remove the whole thing, but use the values:
var originalWidth;
var originalHeight;
embeddedString = embeddedString.replace(/(?:width|height)\s*=\s*["']([0-9]+)["']\s*(?:width|height)\s*=\s*["']([0-9]+)["']/ig, function($0, $1, $2, $3, $4)
{
// $0 = original string
// $1 = either 'width' or 'height'
// $2 = the value of width or height, depending on above
// $3 = either 'width' or 'height'
// $4 = the value of width or height, depending on above
// here you might want to set another value, eg:
originalWidth = $2;
return "";
});