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
  • 89,455
  • 62
  • 89
  • 125

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
  • 412,405
  • 93
  • 575
  • 722
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.