문제

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

도움이 되었습니까?

해결책

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

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

What it matches :

  • [\d\.]+ : a combination of . and digits
  • \) : the end parenthesis
  • $ : the end of the string (you can remove it if you don't want to ensure it's the end of the string)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top