Lua Regex / Pattern Matching Link to heading

In Lua, Regex is handled through string patterns

The pattern '[_%a][_%w]*' matches a sequence that: starts with letter or underscore, followed by zero or more underscores or alphanumeric characters.

Character Classes Link to heading

.all characters
%ccontrol characters
%llower case letters
%ppunctuation characters
%sspace characters
%uupper case letters
%walphanumeric characters
%xhexadecimal digits
%zthe character with representation 0

Example Link to heading

-- Ex. 2: Matches a Markdown main header
-- 1. Match # at the beginning of string (^)
-- 2. Followed by white space
-- 3. Followed by any number (*) of:
--   letters, digits, punctuation characters, or white spaces ('% ')
-- 4. New line
local markdown_title = string.match(content, '^# [% %a%x%p]*\n')