What I want to do:
I want to reformat a bunch of similarly written HTML files in Visual Studio. The html parts may have a different number of lines, but I know that they start with a <div id="some_id">
tag and there is no other <div>
tag enclosed. So how would I write a regex that catches any number of lines in between?
What I tried so far:
I can't use the .
, because it doesn't catch line breaks. But I also don't know how to tell Visual Studio to catch either \n
or .
. I know how to use sets (like [a-z0-9]
) but as soon as you put a .
into them it turns into a literal. So <div id="some_id">[.\n]*?</div>
catches only divs which contain a bunch of dots and new lines
Thanks in advance
In Visual Studio Find and Replace feature, you may match any chars including line breaks by using a [\s\S\r]
character class. For some reason, [\s\S]
does not match the CR (carriage return) symbol.
Your [.\n]
char class only matches a literal .
or a newline.
Thus, use
<div id="some_id">[\s\S\r]*?</div>
^^^^^^^^^^
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With