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 ofasync
(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