ahitt6345
ahitt6345

Reputation: 510

Sublime Text Html Word Counter

I have an HTML document, mystory.html. This document holds the following:

<body>
    <p>Hello World!</p>
    <p>This document holds seven words.</p>
</body>

I want to be able to use cmd + f and find all of the words that are NOT HTML tags via regex. I would download a plugin via package installer that counts words in the HTML, but it does not exist 8(

I have used the following regex to try to do something similar, but the problem with it is that it counts the bod in body and if any tag name length is greater than 1 the regex also selects it. The code is (?:)[a-zA-Z']+(?!>). None of these tags have any properties or css. Basically, I want to count the number of words in the document that ARE NOT HTML TAGS. If anyone knows a plugin, I will also accept that answer.

Upvotes: 2

Views: 477

Answers (1)

Keith Hall
Keith Hall

Reputation: 16105

You could use the regex:

\b[\w']+\b(?!>)
  • word boundary
  • followed by a word
  • followed by a word boundary
  • not followed by >

This returns 7 matches.

html words

Upvotes: 4

Related Questions