Skip to main content
Module 5 · Lesson 2 of 418/32 in the course~15 min
Module lessons (2/4)

Ranges inside classes: `[a-z0-9]`

Lesson preview5 hands-on exercises readyRegex Course · Module 5 — Character classes

Intervals via the dash; combining ranges and single characters.

What you'll learn in this lesson

  • Define compact ranges with the hyphen - ([a-z], [0-9], [A-F]) taking advantage of the Unicode/ASCII code point order.
  • Combining multiple ranges and single characters in the same class, for example for hexadecimal digits or identifiers.
  • Avoid inverted ranges ([z-a]) and the classic [A-z] bug that includes punctuation characters between Z and a.

Overview

Listing all the characters one by one inside [...] quickly becomes inconvenient. Classes accept ranges written with the hyphen -: [a-z] matches any Latin lowercase letter and [0-9] any decimal digit.

Each character has a numeric code (ASCII/Unicode code point). Writing a-z is equivalent to asking the engine: _"is the code of the current character between the code of a (97) and the code of z (122)?"_.

Sections covered in this lesson

  1. 1Mental model: number ranges in the character table
  2. 24 progressive examples step by step
  3. 3Guided practical exercises
  4. 4Quick check
Pro Lesson · Module 5 — Character classes

Unlock "Ranges inside classes: `[a-z0-9]`" and the full Regex Course curriculum

Intervals via the dash; combining ranges and single characters.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Regex Course plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.