2

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"

0

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Mr. Tim. Thank you very much! I knew it was possible, but some regexps are just to much for me :) And now when I'm writing this comment you keep editing yours so I can better understand it. That's brilliant!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.