Special characters

2 snippets across 2 stacks — HTML & CSS, Regular Expressions

HCHTML & CSS

Character Encoding

HC · Document Structure
syntax
<meta charset="UTF-8">
example
<head>
  <meta charset="UTF-8">
</head>

Note Must appear within the first 1024 bytes of the document. UTF-8 handles virtually all global characters and emoji.

RXRegular Expressions

Escaping Special Characters

RX · Basic Patterns
syntax
\. \* \+ \? \( \) \[ \] \{ \} \^ \$ \| \\
example
JS:  'Price: $9.99'.match(/\$\d+\.\d{2}/)
Py:  re.search(r'\$\d+\.\d{2}', 'Price: $9.99')
output
"$9.99"

Note All special regex characters must be escaped with a backslash to match literally. The special characters are: . * + ? ( ) [ ] { } ^ $ | \. In Python raw strings (r'...'), you only escape for regex, not for Python itself.