...

View Full Version : regular expression replace



Phil Jackson
12-12-2009, 01:39 PM
Im sorry im tired and cant think how to put this.

how do i make \\1 and \\2 = margin-bottom:([^;]+); and margin-top:([^;]+);

Sorry again,

Regards.


var regep = /margin-bottom:([^;]+); margin-left:0px; margin-right:0px; margin-top:([^;]+);/;

elementCSS = elementCSS.replace( regep , "margin-bottom:\\1; margin-left:auto; margin-right:auto; margin-top:\\2;");

oesxyl
12-12-2009, 03:10 PM
Im sorry im tired and cant think how to put this.

how do i make \\1 and \\2 = margin-bottom:([^;]+); and margin-top:([^;]+);

Sorry again,

Regards.


var regep = /margin-bottom:([^;]+); margin-left:0px; margin-right:0px; margin-top:([^;]+);/;

elementCSS = elementCSS.replace( regep , "margin-bottom:\\1; margin-left:auto; margin-right:auto; margin-top:\\2;");


cssElement = cssElement.replace(/margin-(top|right|bottom|left):\s*(\d+)[^;]*;/g, function(){
var side = arguments[1], val = arguments[2];
if(side == 'left' || side == 'right'){
return 'margin-' + side + ': auto;';
}
return ('margin-' + side + ': ' + val + (parseInt(val) == 0 ? '' : 'px;'));
}));


best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum