Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,547
    Thanks
    57
    Thanked 148 Times in 147 Posts

    regular expression replace

    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.

    Code:
    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;");
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Phil Jackson View Post
    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.

    Code:
    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;");
    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •