93 words
1 minute
Search and replace with regular expressions in VS Code
Anubhav Gain
2024-02-06

Search and replace with regular expressions in VS Code#

I wanted to replace all instances of this:

`#90 <https://github.com/simonw/sqlite-utils/issues/90>`__

With this:

:issue:`90`

For sqlite-utils issue #306.

I used the VS Code’s Find and Replace tool with regular expression mode turned on (the .* button). I used the following for the find:

`#(\d+) <https://github.com/simonw/sqlite-utils/issues/\1>`__

Note the \1 reference to say “the same thing I captured earlier with parenthesis”. Then I used this as the replace string:

:issue:`$1`

Here the $1 means “the first thing captured with parenthesis”.

Screenshot of the find and replace dialog

The resulting change can be seen in commit e83aef95.

Search and replace with regular expressions in VS Code
https://mranv.pages.dev/posts/search-and-replace-with-regular-expressions-in-vs-code/
Author
Anubhav Gain
Published at
2024-02-06
License
CC BY-NC-SA 4.0