In VSCode I’d like to search for an element (<button
) which has a specific attribute that can be on a new line (data-color
).
Is there a way to do this search using Regex, but avoiding greedy matching?
For example, match this:
<button
id="id"
data-color="blue"
>
but not match this:
<button
id="id"
>
</button>
<div data-color="blue">
I also wonder if there’s more sophisticated ways to search this without using regex? I’m using Vue.js, so assume there’s more advanced parsers than regex.
I’ve tried this but it matches the example I’m trying to avoid:
<button(.|n)+data-color=(.|n)+>
2
Answers
Use a negative character set
Another option could be adding
r
to the negated character class: