Day 29 of 100: Regex — Pattern Matching for Testers
Day 29 of 100 — 100 Days of Playwright with TypeScript Challenge. Phase: JavaScript Fundamentals. JavaScript (Days 1-33) → TypeScript (Days 34-63) → Playwright (Days 64-96) → AI Framework Capstone (Days 97-100).
🎭 Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
Regex validates formats, extracts values, and powers Playwright’s URL and text matching.
Contents
Core Syntax
const emailRe = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
emailRe.test('qa@test.com'); // true
emailRe.test('not-an-email'); // false
const orderRe = /Order #(\d+)/;
const m = 'Order #1234 confirmed'.match(orderRe);
m[1]; // '1234' — capture group
🚀 Level Up Your Playwright
From locators to CI pipelines — build a production-grade Playwright + TypeScript framework step by step.
Cheat Sheet
- \d digit, \w word char, \s whitespace, . any char
- + one or more, * zero or more, ? optional, {3} exactly three
- ^ start, $ end, [abc] char set, (x) capture group
- i flag = case-insensitive, g flag = all matches
Regex in Playwright
// URL matching — the everyday use:
// await expect(page).toHaveURL(/\/orders\/\d+/);
// Text matching, case-insensitive:
// await expect(locator).toHaveText(/welcome back/i);
// getByText with regex:
// page.getByText(/^Submit$/) — exact match, no partials
const price = '$1,299.99';
const num = parseFloat(price.replace(/[$,]/g, '')); // 1299.99
Tomorrow (Day 30): Dates and times — timestamps, formatting, comparisons.
🎓 Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
