Created
May 30, 2021 17:25
-
-
Save muvaf/226916a10a9d5aac5e9a1f9aeabc2cd0 to your computer and use it in GitHub Desktop.
Partial find and replace with regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In most text editors, there is an option to find a string using regex. | |
# But what if you'd like to replace a specific sentence in the expression? | |
# For example, let's say there are following strings in different files: | |
# | |
# NewGeneratorForService(t, "apigatewayv2") | |
# NewGeneratorForService(t, "rds") | |
# | |
# And you'd dike to add a new argument to all these calls and make them like following: | |
# | |
# NewGeneratorForService(t, "apigatewayv2", ackgenconfig.DefaultConfig) | |
# NewGeneratorForService(t, "rds", ackgenconfig.DefaultConfig) | |
# | |
# You need to find occurences with regex: NewGeneratorForService\(t, "(.*)", ackgenconfig.DefaultConfig\) | |
# Notice that (.*), the paranthesis makes it a "group". In the replace box, you can address the groups by index. | |
# | |
# If you write the following in replace box, then you'll be able to replace all occurences automatically! | |
# | |
# NewGeneratorForService\(t, "$1", ackgenconfig.DefaultConfig\) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment