Q:

Regular expression to convert an RGB string to an RGBa string

I am using String#replace() to convert an RGB string into an RGBa one. This is the current code:
inputString = "rgb(255, 182, 121)";
outputString = inputString.replace( "rgb", "rgba" ).replace( ")", ",255)" ).replace( " ", "" );

In the example above, the output will be "rgba(255,182,121,255)". This solution, however, looks a bit convoluted, and I think it could be done more elegantly using a regular expression.
How can I write a regular expression (in Java) to accomplish the same thing as the code above?

A:

Sure you can:
    inputString.replaceFirst("rgb\\((\\d++),\\s*(\\d++),\\s*(\\d++)\\)", "rgba($1,$2,$3,255)");

If you use it more often, better pre-compile the regex with Pattern.compile().

