0Pricing
JavaScript Academy · Lesson

Regex basics — literals, test, anchors, and flags

Create simple regexes, test text, use anchors (^ $), and apply common flags (i, g) for small parsing tasks.

Intro to regex

Goal: Recognize and apply tiny regex patterns.

  • Create a regex literal like /cat/
  • Check with test()
  • Use anchors ^ and $
  • Add flags: i (ignore case), g (global)
Regex basics — literals, test, anchors, and flags — illustration 1

Literal + test()

Create a literal like /cat/ and call test(text) to get true/false.

// Use a regex literal and test() to check presence
const r = /cat/;
console.log("has cat?", r.test("my cat"));
console.log("has cat?", r.test("dog"));
Regex basics — literals, test, anchors, and flags — illustration 2

All lessons in this course

  1. Regex basics — literals, test, anchors, and flags
  2. Groups, Captures, and Replace
  3. Validation & small pitfalls
← Back to JavaScript Academy