%s@{fileID: \(213[0-9]*\)@\='{fileID: '.(submatch(1)-1900)@
I am using this regex search and replace command in vim to subtract a constant from each matching id.
I can do the regex find in VSCode but how can I reference the submatch
for maths & replace? submatch(1)
does not work in VSCode?
Thanks.
You can use the Find control in code or text windows, such as Output windows and Find Results windows, by selecting Edit > Find and Replace or pressing Ctrl+F.
VSCode is using JavaScript-based regex engine, but it is not the same. You cannot use named capturing groups there. There is no specific documentation on the regex used in VSCode. However, if you have a look at the source code, you will see lots of JS code around.
To run a “whole words only” search using a regular expression, simply place the word between two word boundaries, as we did with ‹ \bcat\b ›. The first ‹ \b › requires the ‹ c › to occur at the very start of the string, or after a nonword character.
VS Code allows you to quickly search over all files in the currently opened folder. Press Ctrl+Shift+F and enter your search term. Search results are grouped into files containing the search term, with an indication of the hits in each file and its location.
Given a regular expression of (foobar)
you can reference the first group using $1
and so on if you have more groups in the replace input field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With