Character class
A character class is a regular-expression construct that matches one character belonging to, or excluded from, a specified set, range, or property.
Tiny Python Projects: Learn coding and testing with puzzles and games
A character class is a regular-expression construct that matches one character from a specified set or range.
- How it is used
- Uses character classes to find, replace, extract, and validate constrained text with Python regular expressions.
- How deep it goes
- Explains listed characters, ranges, negation, quantifiers, anchors, and capture-group combinations through runnable examples.
- Examples
- Demonstrates vowel replacement, consonant detection, word transformation, placeholder extraction, password cleaning, and board validation.
- What you can do after
- Apply it via Python's re module to express character sets, exclude characters, and combine classes with broader patterns.
Secrets of the JavaScript Ninja, Third Edition
A character class is a regular-expression construct that matches one character from a specified set or range.
- How it is used
- Selects allowed or excluded characters inside regex patterns for matching, extraction, and string replacement.
- How deep it goes
- Explains bracket syntax, negation, ranges, shorthands, and repetition through patterns; does not examine character-class engine internals.
- Examples
- Uses excluded separators in a roster, lowercase letters in a doubled-word pattern, and hyphenated text converted to camel case.
- What you can do after
- Apply it via JavaScript regular expressions to specify single-character choices and combine them with repetition, captures, or replacement.
Read how Secrets of the JavaScript Ninja, Third Edition explains character class →
Secrets of the JavaScript Ninja, Second Edition
A regular expression construct in square brackets that matches one character from a specified set or range, optionally negated.
- How it is used
- Selects one character from a set or range when a literal character is too restrictive.
- How deep it goes
- Defines explicit, negated, and ranged classes, then works through a newline-matching idiom without an exhaustive regex treatment.
- Examples
- Uses `[abc]`, `[^abc]`, `[a-m]`, and assertions comparing `/.*/` with `/[\S\s]*/` on a string containing a newline.
- What you can do after
- Apply it via JavaScript regular expressions to choose characters from sets and match across newlines.
Read how Secrets of the JavaScript Ninja, Second Edition explains character class →
The Quick Python Book, Fourth Edition
A character class is a regular-expression construct that matches one character from a specified set or range.
- How it is used
- Uses character classes to match alternative characters and construct name patterns within record-matching expressions.
- How deep it goes
- Explains sets, ranges, literal hyphens, and repetition, while deferring a complete account of regular-expression special characters.
- Examples
- Illustrates case alternatives, character ranges, hyphenated names, and records containing names and phone numbers.
- What you can do after
- Apply it via Python's re module to match name and phone records.
Read how The Quick Python Book, Fourth Edition explains character class →
Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS
A character class is a regular-expression construct that matches a character selected from, or excluded by, a specified set or range.
- How it is used
- Filters Windows event-log and text-file content by requiring characters to belong to selected categories or ranges.
- How deep it goes
- Demonstrates \w, \W, combined classes, numeric ranges, and a practical PowerShell pattern without developing regex internals.
- Examples
- Uses computer-account names in Windows security events and log lines containing mixed word, nonword, and numeric characters.
- What you can do after
- Apply it via PowerShell Select-String to locate log messages whose characters meet practical account-name or log-text constraints.
Natural Language Processing in Action, Second Edition
A regular-expression construct that matches one character from a specified set or range.
- How it is used
- Supports precise pattern-based intent recognition for commands and greetings.
- How deep it goes
- Defines ranges and repetition, then demonstrates combined classes in runnable greeting patterns without covering regex internals.
- Examples
- Uses lowercase-letter ranges, greeting strings, whitespace and punctuation classes, and captured names in Python.
- What you can do after
- Apply it via Python's re package to match character ranges and assemble greeting-recognition patterns.
Read how Natural Language Processing in Action, Second Edition explains character class →
Modern C, Third Edition
A character class is a set of characters sharing a property such as being alphabetic, numeric, whitespace, or punctuation.
- How it is used
- Classifies characters for string processing, case conversion, numeric conversion, and formatted input.
- How deep it goes
- Defines common predicates, locale extensions, integer interfaces, and scan-set syntax, then demonstrates classifier-based conversion.
- Examples
- Uses ctype predicates, a hexadecimal-style converter, and scanf sets for vowels and newline-delimited input.
- What you can do after
- Apply character classes via <ctype.h> classifiers, case conversions, conversion routines, and scanf scan sets.
Modern C
A character class is a set of characters sharing a property such as being alphabetic, numeric, or whitespace.
- How it is used
- Supports encoding-independent character inspection, case conversion, string processing, numeric conversion, and formatted input.
- How deep it goes
- Defines standard classifiers, relationships, locale extensions, and scan-set syntax, but defers wider multibyte-character treatment.
- Examples
- Uses hexatridecimal conversion, vowel scanning, and whole-line scanning with a negated newline class.
- What you can do after
- Apply ctype.h classifiers and scanf scan sets to recognize, convert, and selectively read characters.
The Well-Grounded Rubyist, Fourth Edition
The word character class is the regular-expression character class matching letters, numbers, and underscore.
- How it is used
- Constrains regular-expression matches and scans word-like text without accepting every character.
- How deep it goes
- Explains explicit, ranged, negated, predefined, and POSIX classes, including single-character matching and Unicode behavior.
- Examples
- Uses rejected, hexadecimal strings, digit scans, proper names, Unicode letters, and Greek characters as matching examples.
- What you can do after
- Apply it via Ruby regular expressions to recognize constrained characters, scan word-like runs, and choose Unicode-aware alternatives.
Read how The Well-Grounded Rubyist, Fourth Edition explains character class →
Python How-To
A character class is a regular-expression shorthand or bracketed construct that matches characters sharing a specified property or membership condition.
- How it is used
- Builds regular-expression patterns that select characters by property, explicit membership, range, or exclusion.
- How deep it goes
- Explains shorthand, ranges, combinations, complements, and bracket syntax with matching output, while deferring broader pattern operators.
- Examples
- Uses [lmn], [a-z], [^a], \d, \D, \s, \S, \w, and \W against short test strings.
- What you can do after
- Apply it via regular-expression search and find-all functions to locate selected characters in strings.
Also covered in
What to know first
- regular expressionA regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- PythonPython is a high-level, general-purpose, dynamically typed programming language with readable syntax and support for multiple programming paradigms.
- stringA string is a programming-language value representing textual data as an ordered sequence of characters or encoded units.
- ASCIIASCII is a 7-bit character-encoding standard that assigns numeric codes to 128 basic Latin characters, symbols, punctuation marks, digits, and control characters.
Related concepts
- regular expressionpart of · A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
- digitincludes · A digit is a single symbol representing a numerical value or place in a positional numeral system, such as 0 through 9 in decimal notation.
- word characterincludes · A word character is a character that belongs to a regular expression engine’s word-character class, commonly including letters, digits, and underscores.
Questions about character class
What is character class?
A character class is a regular-expression construct that matches one character belonging to, or excluded from, a specified set, range, or property.
Which Manning books explain character class?
Tiny Python Projects: Learn coding and testing with puzzles and games, Secrets of the JavaScript Ninja, Third Edition, Secrets of the JavaScript Ninja, Second Edition, The Quick Python Book, Fourth Edition, Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS, Natural Language Processing in Action, Second Edition, Modern C, Third Edition, Modern C and 2 more.
What should I know before learning character class?
Manning books that teach character class usually introduce regular expression, Python, string and ASCII first.
What kinds of character class are there?
Kinds of character class include digit, negated character class and word character.
What is character class part of?
Character class is part of regular expression. A regular expression is a formal pattern notation that describes sets of strings and specifies how text can be matched, searched, or transformed.
What are the parts of character class?
Character class includes regular-expression character range.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.









