Trying to search-replace in Visual Studio Code, I find that its Regex flavor is different from full Visual Studio. Specifically, I try to declare a named group with string (?<p>[\w]+)
which works in Visual Studio but not in Visual Studio Code. It'll complain with the error Invalid group
.
Apart from solving this specific issue, I'm looking for information about the flavor of Regexes in Visual Studio Code and where to find documentation about it, so I can help myself with any other questions I might stumble upon.
Full Visual Studio uses .NET Regular Expressions as documented here. This link is mentioned as the documentation for VS Code elsewhere on Stackoverflow, but it's not.
Rob Lourens of MSFT wrote that the file search uses Rust regex. The Rust language documentation describes the syntax.
Alexandru Dima of MSFT wrote that the find widget uses JavaScript regex. As Wicktor commented, ECMAScript 5's documentation describes the syntax. So does the MDN JavaScript Regular Expression Guide.
The find in files sidebar does not support (?=foobar)
whereas the find in file widget does support that lookahead syntax.
To find/replace with groups, use parentheses ()
to group and $1
, $2
, $3
, $n
to replace.
Here is an example.
Before:
After: