Small post – just because I needed it recently – and it made me think of this little gem that I still had to share: what if you have to search over multiple lines in multiple files in VSCode .. something that actually might happen more than you want to admit.
I actually never knew how to do this decently, until I came across this tweet:
The core of the “solution” is this RegEx: [\s\S\n]+?
To explain you simply:
\s
: matches any whitespace character (space, table, line breaks)\S
: matches any character that is not a whitespace character\n
: matches a line feed character (code 10)[]
: matches any character in this set+
: matches one or more of the preceding token – in this case, the set of any character including the line feed?
: causing the preceding quantifier to match as few as possible. So – take all, but as few as you can.
Here are a few examples:
Find all translation-info spread over multiple lines..
<trans-unit id="Enum[\s\S\n]+?<\/source>
![<trans-unit id= "Enum
1931 results in 75 files - Open in editor
BASE - App
iFacto Base.fr-BE.xlf BASE - App
<trans-unit 50607090
<trans-unit id="Enum 50607090
<trans-unit 50607090
• Translations 141
- Enumvalue 3263198591
- Enumvalue 4190668035
- Enumvalue 2004364593
- Property 28
- Propefty 28
- Property 28](https://www.waldo.be/wp-content/uploads/2022/01/image.png)
Or find “CLEAN19” code snippets with
if not CLEAN19[\s\S\n]+?#endif
![](https://i0.wp.com/www.waldo.be/wp-content/uploads/2022/01/image-1.png?fit=847%2C589&ssl=1)
And don’t forget to put your search in VSCode in “RegEx” mode (ALT+R)!
![](https://www.waldo.be/wp-content/uploads/2022/01/image-2.png)
Thank you, phenno, for sharing! It might not work for all cases, it might need some finetuning – but for the searches I needed, it always did its job ;-).