Code Explainers
Code explainers tagged #html-escaping
javascript
const TOKEN_SPECS = [ ["comment", /^\/\/[^\n]*|^\/\*[\s\S]*?\*\//], ["string", /^"(?:\\.|[^"\\])*"|^'(?:\\.|[^'\\])*'|^`(?:\\.|[^`\\])*`/], ["number", /^0[xX][\da-fA-F]+|^\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/],
Building a syntax highlighter tokenizer
tokenizer
regular-expressions
lexing
Intermediate
8 steps
javascript
function escapeHtml(str) { return str.replace(/[&<>"']/g, (ch) => ({ '&': '&', '<': '<',
Safely highlighting search matches in text
html-escaping
regex
search-highlighting
Intermediate
7 steps