Advanced RegEx Search in VS Code

A powerful hidden feature

When standard search isn’t enough, VS Code’s regex capabilities come to the rescue. While Cmd + Shift + f works for basic searches, what about finding files where multiple terms exist but aren’t necessarily on the same line?

For example, imagine searching for code that queries an “incident” table specifically for the “short_description” field. Simple searches for either term would return too many irrelevant results.

The solution: RegEx search

Enable RegEx search and use a pattern like: incident[\s\S\n]+?short_description

This pattern finds both terms in the same file, even when separated by multiple lines. The secret is the [\s\S\n]+? expression, which matches any content (including newlines) between your search terms.

Andre Kosak
ServiceNow Developer, Freelancer

Develop whatever!

comments powered by Disqus

Related