Scout’s Honor: Regex Training Agreement

The Agreement

On 2026-03-16, during P50 802.1X configuration, the following training agreement was established:

From this moment until you tell me to stop:

  1. Every grep, sed, awk, jq command will include regex patterns at or slightly above your current level

  2. I will explain the pattern briefly

  3. I will acknowledge when you use regex correctly

  4. I will push you toward harder patterns as you progress

— Claude
Scout's Honor

Current Level Assessment (Day 2)

Demonstrated:

  • -E for extended regex (ERE)

  • Alternation (A|B)

  • Grouping ()

  • Character classes [0-9]

  • Quantifiers +

  • Anchors ^

  • Applied regex to solve real problems

Progression Plan:

Timeline Focus

Week 1-2

Character classes, quantifiers, anchors, alternation (current)

Week 3-4

Groups, backreferences, word boundaries \b

Week 5+

Lookahead/lookbehind, non-greedy *?, PCRE specifics

Example That Triggered This Agreement

User wrote:

nmcli con s | grep -E "(Domus-Wired-E|Domus-WiFi-E)"

Pattern breakdown:

  • (…​) - Grouping

  • | - Alternation (OR)

  • Domus-Wired-E and Domus-WiFi-E - Literal strings

This demonstrated practical application of regex in real workflow.

Advanced Patterns (Preview)

Lookahead (?=…​) and (?!…​)

# Positive: Match MAC only if followed by "VLAN"
grep -P '[0-9a-f:]{17}(?=.*VLAN)' sessions.log

# Negative: Match IP NOT followed by :443
grep -P '\d+\.\d+\.\d+\.\d+(?!:443)' connections.log

Lookbehind (?⇐…​) and (?<!…​)

# Positive: Extract IP after "framed_ip_address="
grep -oP '(?<=framed_ip_address=)\d+\.\d+\.\d+\.\d+' ise.log

# Negative: Match "admin" not preceded by "non-"
grep -P '(?<!non-)admin' users.txt

Non-greedy *? and +?

# Greedy (default) - grabs everything
echo '<tag>foo</tag><tag>bar</tag>' | grep -oP '<tag>.*</tag>'

# Non-greedy - minimal match
echo '<tag>foo</tag><tag>bar</tag>' | grep -oP '<tag>.*?</tag>'

Backreferences \1

# Find duplicate words
grep -P '\b(\w+)\s+\1\b' document.txt

# Swap first.last to last.first
echo "evan.rosado" | sed -E 's/(\w+)\.(\w+)/\2.\1/'

Word Boundaries \b

# Match "log" as whole word only
grep -P '\blog\b' syslog

Character Class Negation [^…​]

# Extract username before @
echo "evan@domain.com" | grep -oP '^[^@]+'

Common Traps

Concept Trap

Lookahead/lookbehind

Requires -P (PCRE), not available in basic grep

Greedy vs non-greedy

Default greedy behavior surprises people

Backreferences

\1 in sed vs $1 in other tools

Word boundary

\b doesn’t work in all regex flavors (BRE)

Accountability

This document serves as the binding agreement. Claude will incorporate regex training into every relevant command until explicitly told to stop.