codex-lv3-may-2025

Level Navigation: 1 (2ℹ️) 3 4 5 6 (7ℹ️) (8ℹ️) (9ℹ️) 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 (37ℹ️) 38⚡ 39⚡ 40⚡ 41⚡ 42 43⚡ 44⚡ 45 46 (47ℹ️)

Level 35: Key Takeaways, Next Steps, and Resources

Key Takeaways

  1. Red: Write tests first that describe what you want
  2. Green: Write the minimum code to make tests pass
  3. Refactor: Improve code while keeping tests green
  4. Regex: Use regular expressions to match patterns of characters
  5. Character classes: Use [] to match any of several characters
  6. \W: Matches any non-word character (punctuation, symbols)

Common Regex Patterns

Here are some useful patterns:

// Replace spaces (simple string replacement)
text.replaceAll(' ', '_')

// Replace specific punctuation
text.replaceAll(/[!?,]/g, '_')

// Replace all punctuation (non-word characters)
text.replaceAll(/\W/g, '_')

// Replace everything except letters, numbers, and underscores
text.replaceAll(/[^a-zA-Z0-9_]/g, '_')

Quick Regex Reference for Beginners

Here are some common regex patterns you might use:

Pattern Matches Example
[abc] Any of these characters (a, b, or c) /[abc]/g matches “a”, “b”, or “c”
[!?,] Any of these punctuation marks /[!?,]/g matches “!”, “?”, or “,”
\W Any non-word character (punctuation, symbols) /\W/g matches “!”, “?”, “,”, etc.
\w Any word character (letters, numbers, underscore) /\w/g matches “a”, “1”, “_”
\s Any whitespace (spaces, tabs) /\s/g matches “ “ (space)
\d Any digit (0-9) /\d/g matches “0” through “9”
[^abc] NOT any of these characters /[^abc]/g matches anything except a, b, or c
+ One or more of the previous /\W+/g matches one or more punctuation marks
* Zero or more of the previous /\d*/g matches zero or more digits
? Zero or one of the previous /\d?/g matches zero or one digit

Note: In JavaScript, regex patterns are written between forward slashes: /pattern/

Next Steps

Resources