I need to replace part of strings, one is a RGBA and the other is a RGB, both from a CSS style-sheet on Textbox in Visual Basic.
The thing is a little more complicated, the alpha value varies and sometimes it has spaces, I guess regex is the better way to do it, but I don't know how, let me put some examples:
// RGBA
rgba(15,90,110,0.4);
rgba(15, 90,110, 0.2);
rgba(15, 90, 110, 0.35);
rgba(15, 90, 110,0.14);
rgba(15,90, 110,0.1) !important;
rgba(15,90, 110, 0.1);
// RGB
rgb(21, 25, 140);
rgb(21,25, 140);
rgb(21, 25,140);
rgb(21,25,140);
rgb(21, 25,140) !important;
// And so on...
What I'm using to replace it is the Replace function from Visual Basic:
' RGBA
TextBox2.Text = TextBox1.Text.Replace("rgba(15,90,110,0.35)", "rgba(40,133,183,0.35)")
' RGB
TextBox2.Text = TextBox1.Text.Replace("rgb(21,25,140)", "rgb(40,175,81)")
The problem comes when the alpha value changes or when it has spaces... For the RGB I replace each spacing option, but I have to do it with different colors, and the code gets too long (4 lines of code per color), is there a way to do it with regex too?
Note: I don't replace it including ; because sometimes it has the important flag, so that way I'll keep it as it is, by the way, I'm using Visual Studio 2012.
Can somebody help me out, please? Thank you in advanced.