0

In VSCode: I would like to do a wildcard replace of:

rgb(1, 1, 1 ,1)

with:

rgba(1, 1,1 ,1)

Essentially when an alpha value is specified, the datatype should be changed from "rgb" to "rgba". Where alpha is not specified e.g rgb(1,1,1) - they should remain unchanged.

I tried:

Find: rgb(.*,.*,.*,.*) Replace: rgba($1)

which obviously did not work. What would be the correct regex syntax to achieve this? Thank you.

Update: Please note that some locations there are spaces before/after commas. Not consistent.

Toto
  • 86,179
  • 61
  • 85
  • 118

2 Answers2

1

To match with any amount of whitespace around the numbers:

Search: rgb(?=\((\s*\d+\s*,){3}\s*\d+\s*\))
Replace: rgba 
Bohemian
  • 389,931
  • 88
  • 552
  • 692
0
Search: rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)
Replace: rgba($1, $2, $3, $4)

This will match any amount of whitespace and will fix them after replace.