Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode regex find & replace submatch math?

%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.

like image 413
Rakka Rage Avatar asked Jan 05 '16 18:01

Rakka Rage


People also ask

How do I find and replace in VSCode?

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.

What type of regex does VSCode use?

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.

How do you match a word in regex?

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.

How do I find code in Visual Studio code?

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.


1 Answers

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.

like image 152
Benjamin Pasero Avatar answered Oct 10 '22 10:10

Benjamin Pasero