Regex Session 01: Absolute Basics

Starting from zero. This session covers literal matching, the concept of metacharacters, and your first patterns using regexr.com.

Pre-Session State

  • Opened regexr.com

  • Can write simple grep commands

  • Understand "pattern matching" concept vaguely

Setup

  1. Open regexr.com in browser

  2. Clear the default pattern (select all, delete)

  3. Paste this test text in the "Text" area:

The quick brown fox jumps over the lazy dog.
IP: 192.168.1.100
MAC: AA:BB:CC:DD:EE:FF
User: evanusmodestus logged in at 10:30:45
Error: Connection refused to 10.50.1.20
VLAN 100 is active on port Gi1/0/24
Log: 2026-03-15T14:30:00 INFO Server started

Lesson 1: Literal Characters

Concept: Most characters match themselves literally.

Exercise 1.1: Find a word

Type in the pattern field:

fox

What happens: The word "fox" is highlighted.

Key insight: Regex is case-sensitive by default. Fox won’t match fox.

192

What happens: "192" in the IP address is highlighted.

error

What happens: Nothing matches! The text has "Error" with capital E.

Fix: Toggle the "case insensitive" flag (i) in regexr, or use Error.

Lesson 2: The Dot Metacharacter

Concept: The dot . matches ANY single character (except newline).

f.x

What happens: "fox" matches - the . matched o.

Type:

1..168

**What happens:** "192.168" matches - dots matched `9` and `2`.

**Problem:** We matched digits, but `.` is too greedy. What if we want literal dots?

== Lesson 3: Escaping Metacharacters

**Concept:** Backslash `\` makes a metacharacter literal.

=== Exercise 3.1: Match literal dot

Type:

192\.168

**What happens:** "192.168" matches - the `\.` matched literal `.`

=== Exercise 3.2: Full IP octet pattern

Type:

192\.168\.1\.100

**What happens:** The full IP matches exactly.

== Lesson 4: Character Classes

**Concept:** Square brackets `[]` define a set of characters to match.

=== Exercise 4.1: Match digits

Type:
**What happens:** ALL digits in the text are highlighted individually.

=== Exercise 4.2: Match hex characters

Type:
**What happens:** All uppercase A-F letters match (from MAC address).

=== Exercise 4.3: Combine ranges

Type:
**What happens:** All hex characters (uppercase, lowercase, digits) match.

== Lesson 5: Quantifiers (Basic)

**Concept:** Quantifiers specify how many times a pattern should match.

=== Exercise 5.1: Plus (+) - one or more

Type:

[0-9]+

**What happens:** Entire numbers match as units (192, 168, 1, 100, etc.)

=== Exercise 5.2: Asterisk (*) - zero or more

Type:

[A-Z]*

**What happens:** Uppercase sequences match, but also empty strings (many zero-length matches).

=== Exercise 5.3: Question mark (?) - zero or one

Type:

logs?

What happens: Matches "log" or "logs" (the 's' is optional).

Summary: What You Learned

Concept Syntax Example

Literal match

Just type it

fox matches "fox"

Any character

.

f.x matches "fox", "fax", "f1x"

Escape metachar

\

\. matches literal "."

Character class

[…​]

[0-9] matches any digit

Range

[a-z]

[A-F] matches A through F

One or more

+

[0-9]+ matches "192"

Zero or more

*

a* matches "", "a", "aaa"

Zero or one

?

logs? matches "log" or "logs"

Exercises to Complete

Before closing regexr, try these:

  1. [ ] Match all MAC address octets: [A-F0-9]+

  2. [ ] Match the username after "User: ": (hint: literal match)

  3. [ ] Match "VLAN" followed by a space and number: VLAN [0-9]+

  4. [ ] Match time format HH:MM:SS: :[0-9]:[0-9]+

Post-Session Reflection

What clicked:

  • <Write what made sense>

What’s still fuzzy:

  • <Write what needs more practice>

Connection to work:

  • <How will you use this?>

CLI Application

Try these in your terminal:

# Find lines with IP addresses (basic)
echo "Server 192.168.1.1 is up" | grep -E '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'

# Find lines with MAC addresses
echo "MAC: AA:BB:CC:DD:EE:FF" | grep -E '[A-Fa-f0-9]+:[A-Fa-f0-9]+'

Next Session

Session 02: Character Classes & Quantifiers - Deep dive into \d, \w, \s, {n,m} quantifiers.

Session Log

Timestamp Notes

Start

<Record when you started>

End

<Record when you finished>

Duration

<Actual time spent>