Why this regex doesn't work in vscode but works in another site?


I don’t know much about regex, but I’m trying to use this regex made by chatGPT in vscode but it returns nothing as result. But when I try to use in another site like https://regex101.com/, the string matches.



Pattern that matches in the site:

                throw new ApiResponseError(
                    new Error(`Required parameters of the '${worksheetDefinitions.worksheetName}' worksheet were not informed`),

Note the blank spaces, i need them in the regex as well.

Is there any configuration I need to do?

I tried to change the regex, search for solutions but it keeps returning nothing. I expected that the regex works like in the site.

>Solution :

You can make any regex for Visual Studio Code match across line breaks if you specify \n{0} anywhere inside the pattern, the most convenient places are start and end of the pattern. I’d recommend putting it at the start so as not to break any specific regex constructs if you are not familiar with regular expressions that much.

So, the rule is \n{0} + YOUR_REGEX.

VSCode regex engine requires \n to be present in the pattern so that any construct like \s or [^"] could match line break chars, and defining a "match zero newlines" pattern does the job.

In your case, you can use


If you have other issues matching any character with a VSCode regex, see Multi-line regular expressions in Visual Studio Code.

Leave a ReplyCancel reply