I would like to use regular expressions in the VSCode search/replacement widget.
Regular expressions vary depending on the implementation, so I would like to know what regular expressions are available.
For example, \w
matches a
other than ASCII characters.
What is the regular expression engine in the VSCode Search/Replace widget?
https://stackoverflow.com/questions/42179046/what-flavor-of-regex-does-visual-studio-code-use received the following response:
JavaScript Regex in the Find/Replace in File Widget
Alexandru Dima of MSFT wrotte that the find widget uses JavaScript regex.As Wicktor commented, ECMAScript5's documentation descriptions the syntax.Sodes the MDN JavaScript Regular Expression Guide.
It seems to be using JavaScript Engine.
However, this answer refers to the answer in the 2016 Github Issue.
I would like to know if it is the same for the 2022 Visual Studio Code.
The following was verified in VSCode 1.72.2:Please note that future version upgrades may change the behavior.
Simply put, the files that are open in the editor seem to use the V8 regular expression engine as they are, but the editor uses ripgrep to search for unopened files.Let's take a closer look.
I didn't follow the source code in detail, but because of its JavaScript-specific behavior, I think I'm still using the V8 regular expression engine (not sure if the Chromium side is Node.js side or both).
The reason is that \s
gets stuck in the U+FEFF (except for the leading U+FEFF which is the BOM).The ECMAScript regular expression \s
is equivalent to [\f\n\r\t\v\u00a0\u1680e\u180e\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\uffff]
, and is a fairly rare regular expression engine that includes U+FEFF.In many other regular expression engines, besides [\t\r\n\f\v]
, [\p{White_Space}]
(Rust) and [\p{Z}]
(.NET) and my own list (Perl?) of Unicode (Unit) category does not include U+FEFF.
In addition to Search (which refers to the Search box shown in Ctrl-F), Search (which refers to the Search view on the left shown in Ctrl-Shfit-F) is the same.This is probably because even if the file is unsaved, the search is performed on the half-written text, so the open file must be different from the search for the unopened file described below.
Because files that are not open cannot be searched in the Search box, it is about the behavior of searching for all files in the workspace in the Search view.I'm following you more closely, so I'll explain it to you.
The ripgrep that you will be entrusted with the search is included as the running binary.If you have a user installation on Windows, it should be %LOCALAPPDATA%\Programs\Microsoft VS Code\resources\app\node_modules.asar.unpacked\@vscode\ripgrep\bin\rg.exe
.This will be done as it is.In my VSCode 1.72.2 for Windows, ripgrep 13.0.0 was included.
Let's take a look at the source code. In https://github.com/microsoft/vscode/blob/1.72.2/src/vs/workbench/services/search/node/ripgrepTextSearchEngine.ts, the following is true:
import {rgPath} from '@vscode/ripgrep';
@vscade/ripgrep is a Microsoft prebuild of ripgrep, Ripgrep-prebuild and run the binary code in and run it.Since the imported You can see what options are actually running on Process Explorer in Help > Open Process Explorer while the search is running.(The search may end soon, so try it in a directory (such as root) with lots of files.) ripgrep is built with Rust, and the standard search engine is Rust regular expression engine, but you can use PCRE2 separately (does VSCode come with a static link?).Rust's regular expression engine does not have "forward read" or "back read" features, but PCRE2 also supports "forward read" or "back read" features. PCRE2 can be used either by specifying the option to use PCRE2 or by using PCRE2 only when necessary, for example, by auto-selecting options with "pre-read" or "post-read".VSCode always sets the auto-select Just a little reminder that even with ripgrep searches, the grammar of the regular expressions available is limited to those available in JavaScript (as noted in the previous section, "Reference") and the open files use V8 regular expressions to be consistent with their behavior. Regular Expression Engine for VSCode Search/Replacement (regardless of Search View Search box) rgPath
is not included in asar, rgDiskPath
changed to a unique path is executed with by RipgrepTextSearchEngine#provideTextSearchResults()
.Engine used by ripgrep
--engine auto
option, so it switches only when necessary (reADME in ripgrep says -engine auto-hybrid
, but it doesn't seem to be a problem).(There is always a search.usePCRE2
option that uses PCRE2, but it was created as a response when there was no automatic selection, and it is now deprecated (deprecated).Reference)
© 2024 OneMinuteCode. All rights reserved.