Coding/Learn/perl/perl regex character classes quantifiers
Perl Programming & Scripting Automation Complete Course
01.Introduction to Perl & Scripting Philosophy
02.Syntax Rules, Comments & Strict Pragmas
03.Scalars: Numbers, Strings & Sigils ($)
04.Operators: Math, Dot (.) Concatenation & Comparisons
05.Booleans, Truth Values & defined()
06.Standard I/O: print, say & chomp
07.Conditional Branching: if, elsif & else
08.The unless Statement
09.Statement Modifiers (Postfix Conditionals)
10.Ternary Operator & Short-Circuit Logic
11.Switch Dispatch & Table Branching
12.Variable Scope: my, state & our
13.While & Until Loops
14.C-Style Three-Part for Loops
15.Foreach Loops & The Default Variable ($_)
16.Loop Control: next, last & redo
17.Labeled Loops & Nested Control
18.Postfix Loops (Modifier Loops)
19.Array Fundamentals: Sigil (@) & Indexing
20.Quote Words (qw//) & List Assignments
21.Stack & Queue Ops: push, pop, shift & unshift
22.Array Slices & Range Operators
23.The splice() Swiss Army Knife
24.Functional List Processing: map, grep & sort
25.Hash Fundamentals: Sigil (%) & Fat Comma (=>)
26.Iterating Hashes: keys, values & each
27.Key Management: exists vs defined & delete
28.Hash Slices (@hash{keys})
29.Sorting Hashes by Values & Keys
30.Nested Data Structures & Arrow Syntax
31.Subroutines: Definition & Arguments (@_)
32.Return Values & Modern Subroutine Signatures
33.References & Dereferencing Operators
34.Anonymous Arrays ([]) & Anonymous Hashes ({})
35.Anonymous Subroutines & Closures
36.Context Sensitivity: Scalar, List & wantarray
37.Regular Expression Basics & Binding (=~)
38.Character Classes, Shortcuts & Quantifiers
39.Capturing Groups ($1, $2) & Named Captures
40.Search & Replace: Substitution Operator (s///)
41.Text Tokenization: split & join
42.Lookarounds, Word Boundaries & Anchors
43.File I/O: Three-Argument open() & Reading Streams
44.Writing & Appending: Modes (>) and (>>)
45.File Test Operators & Directory Operations
46.Executing System Commands: system(), qx// & $?
47.CLI Arguments (@ARGV) & Environment (%ENV)
48.Packages, Modules & the 1; Convention
49.Object-Oriented Perl: bless & Constructors
50.OOP Inheritance & Method Overriding
51.CPAN & JSON Serialization (JSON::PP)
52.Capstone: Apache/Nginx Web Server Access Log Parser
53.Comprehensive Perl Mastery Assessment Quiz
54.Production Capstone: Multi-Source ETL & Reporting Engine
55.Scripting & Automation Certified Specialist Exam
Course Certificate0%

Complete all lessons to earn

LearnCharacter Classes, Shortcuts & Quantifiers
38 / 55 0%
Lesson 38 of 55
9 mins read

Character Classes, Shortcuts & Quantifiers

PreviousNext Lesson
In Plain English

Character classes match categories of characters (`\d` for digits, `\w` for word characters, `\s` for whitespace). Quantifiers (`+`, `*`, `?`, `{min,max}`) control repetition counts.

Deep Dive: How It Works

Shortcuts: `\d` (digits [0-9]), `\w` (word [a-zA-Z0-9_]), `\s` (whitespace [ \t\r\n\f]).

Negated Shortcuts: `\D` (non-digit), `\W` (non-word), `\S` (non-space).

Quantifiers: `+` (1+), `*` (0+), `?` (0 or 1), `{n,m}` (n to m times).

Non-Greedy Modifiers: `+?` and `*?` match the minimum possible characters.

PointCore Rules to Remember

Point star
Built-in Character Classes: `\d`, `\w`, `\s` speed up common pattern recognition.
Point star
Greedy vs Lazy: Append `?` to make quantifiers non-greedy (lazy).

Live Interactive Example

Hit Run Code to see it live
Validating IP and Port Patterns
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Output Console
Click "Run Code" to view the rendered output.
How it works: \d+ captured the numeric port and <.+?> matched the opening tag non-greedily.

Your Turn: Micro Challenge

No pressure! Edit the starter code below and test your solution with instant feedback.

Micro Exercise

Extract User ID with \d+

  • PointSet `my $text = "Order id: 9874 completed";`
  • PointUse `if ($text =~ /id:\s+(\d+)/)` and print `"ID: $1\n"`.
1
2
3
4
5
Sandbox Output
Click "Run & Check" to test your solution.

Finished reading and practicing?

Mark this lesson as completed to update your course progress.

PreviousNext Lesson
Overview100 SheetLearnCertificates