Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    JSJavaScript

    Getting started

    • What is JavaScript?
    • Variables: let, const and var
    • Data types
    • Type conversion

    Operators and strings

    • Arithmetic and assignment
    • Comparison and logic
    • Strings and template literals
    • String methods
    • Numbers and Math

    Control flow

    • Conditions: if and else
    • switch and the ternary operator
    • Loops: for and while
    • Challenge: FizzBuzz

    Functions

    • Functions
    • Arrow functions
    • Parameters: default, rest and spread
    • Scope and closures
    • Callbacks and higher-order functions

    Arrays

    • Array basics
    • map, filter and find
    • reduce and sorting
    • Destructuring

    Objects

    • Object basics
    • Copies and references
    • Methods and this
    • JSON and optional chaining

    Classes and OOP

    • Classes
    • Inheritance

    JavaScript in the page

    • Controlling the page (DOM)
    • Creating elements
    • Events
    • Forms and validation
    • Saving in the browser (localStorage)

    Errors and async

    • Handling errors: try and catch
    • Timers and the event loop
    • Promises
    • async and await
    • Fetching data from an API

    Practical tools and techniques

    • Searching with regular expressions
    • Cancellation and stale results
    • Testing and debugging JavaScript

    Modern JavaScript and a project

    • Map and Set
    • Dates and localised formatting
    • Modules: import and export
    • Project: a complete to-do app
    JavaScript

    Practical tools and techniques · Lesson 39 of 45

    Searching with regular expressions

    Text patterns, test, match and replace.

    8 minutes2 games

    A RegExp describes a text pattern. /cat/i searches case-insensitively. test returns a boolean; match retrieves matches. ^ anchors the start and $ the end; \d matches a digit and + repeats one or more times.

    JavaScript
    console.log(/^\d+$/.test("123"))
    console.log(/cat/i.test("Cat nap"))
    console.log("Order 12 and 7".match(/\d+/g))
    console.log("a   b".replace(/\s+/g, " "))
    ToolUse

    i

    Ignore case

    g

    Global matching

    ^...$

    Match the whole string

    Important

    test on a global or sticky RegExp changes lastIndex, so repeated calls can differ. Independent validation usually does not need g.

    Interview question

    Can a simple email pattern prove the address exists?

    What's the output?

    console.log(/^a+$/.test("aaa"))
    console.log(/^a+$/.test("baaa"))

    What will this code print?

    Exercise

    Replace each whitespace run with one space and print it.

    Expected output: Learn JS today

    JavaScript
    const text = "Learn   JS  today"
    

    Learn more from

    • javascript.info: regexp-introductionjavascript.info
    • MDN: further readingdeveloper.mozilla.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousFetching data from an APINextCancellation and stale results
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.