mdmb
mdmb

Reputation: 5293

VSCode - find and replace with regexp, but keep word

I have multiple occurance of src={icons.ICON_NAME_HERE} in my code, that I would like to change to name="ICON_NAME_HERE".

Is it possible to do it with regular expressions, so I can keep whatever is in code as ICON_NAME_HERE?

To clarify:

I have for example src={icons.upload} and src={icons.download}, I want to do replace all with one regexp, so those gets converted to name="upload" and name="download"

Upvotes: 2

Views: 1126

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522797

Try searching on the following pattern:

src=\{icons\.([^}]+)\}

And then replace with your replacement:

name="$1"

In case you are wondering, the quantity in parentheses in the search pattern is captured during the regex search. Then, we can access that captured group using $1 in the replacement. In this case, the captured group should just be the name of the icon.

Upvotes: 5

Related Questions