mhartington
mhartington

Reputation: 7025

Vim Regex for html

Working with vim regexes for folding html, trying to ignore html tags that start and end on the same line.

So far, I have

if line =~# '<\(\w\+\).*<\/\1>'
  return '='
endif

Which works fine for tags like <a></a>, but when dealing with custom elements, I run into issues since there is a hyphen in the tag name.

Like for example, this element

<paper-input label="Input label"></paper-input>

What needs to change in the regex to also catch the hyphen?

Upvotes: 2

Views: 427

Answers (1)

dbosky
dbosky

Reputation: 1641

The correct regex (updated because of this link) is:

<\([^ >]\+\)[ >].*<\/\1>

or

<\([^ >]\+\)\>.*<\/\1>

This is important [^ >]. This will match any character until whitespace or > i.e. it will match both a and paper_input

Upvotes: 2

Related Questions