Extract html tags with PCRE regex

Verified
Added by iNTERFACEWARE

How to extract the tags from a string of html, using PCRE regex with string.rxmatch()

Source Code
-- extract HTML tags from a string
local s = '<a href="#hello_world">Hello world link</a>'
local tags = ''
for k in s:rxmatch('(<[^>]+>)') do
trace(k)
tags = tags..k
end
trace(tags)
Description
How to extract the tags from a string of html, using PCRE regex with string.rxmatch()
Usage Details

Use string.rxmatch() to find the html tags within a string. The code collects the tags that are found, thereby producing an empty set of tags.

How to use the snippet:

  • Paste the code into your script
  • Inspect the annotations to see how it works