Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devjmetivier/7d1d92c96f7e1b70bd987801af954d32 to your computer and use it in GitHub Desktop.
Save devjmetivier/7d1d92c96f7e1b70bd987801af954d32 to your computer and use it in GitHub Desktop.
Multiline Regular Expression Search in VS Code

From Stackoverflow

start_text.*?(.|[\n])*?end_text

with start_text and end_text being the bounds of your multiline search.

breaking down the regex .*?(.|[\n])*?:

  • .*? will match any characters from your start text to the end of the line. The ? is there to ensure that if your end_text is on the same line the .* wont just keep going to the end of the line regardless (greedy vs lazy matching)
  • (.|[\n]) means either a character\whitespace or a new line
  • *? specifies to match 0 or more of the expression in the parentheses without being greedy.

Examples:

  • use client.*?(.|[\n])*?async will match from the beginning of all "use client" directives in React, and check up to the first instance of async (this is useful for finding client components defined as async incorrectly)
  • <meta.*?(.|[\n])*?/> will match from the beginning of all meta tags to the end of the respective tags
  • <script.*?(.|[\n])*?</script> will match from the beginning of all script tags to the respective closing tags
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment