javascriptregexreplacergba

Replacing\Changing Alpha in RGBA JavaScript


I'm trying to change the Alpha in RGBA, from some reason replace acts strange and instead of resulting with: "rgba(30, 43, 2, A)" i end up with: "A".

Here is the code:

var color="rgba(30, 43, 2, 0.498039)";
color = color.replace(/^.*,(.+)\)/gi,"A");
alert(color);

JS Fiddle Demo


Solution

  • I don't get your logic but you can do this :

    color = color.replace(/[\d\.]+\)$/g, 'A)')
    

    What it matches :