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.

Frequently asked questions

How does HTML & CSS handle special characters?
This task is covered in 2 stacks on this page: HTML & CSS, Regular Expressions. The "Character Encoding" snippet in HTML & CSS uses `<meta charset="UTF-8">`.
Which code does the HTML & CSS example use?
The "Character Encoding" snippet uses `<meta charset="UTF-8">`, from the Document Structure section of the HTML & CSS cheat sheet.
Which stacks cover "special characters" on this page?
HTML & CSS, Regular Expressions. Together they hold 2 copy-ready snippets for this task.
Is there anything to watch out for?
Yes. For "Character Encoding": Must appear within the first 1024 bytes of the document. UTF-8 handles virtually all global characters and emoji.