• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Conditionals○Demo: Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Demo: Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Demo: Stop a Ticket Scan○Challenge: Number Guess Referee○Demo: Rainfall Routing Walkthrough○Exercise: Score Batch Report✦Module Quiz
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Demo: Ticket Pricing Walkthrough○Exercise: Shipping Labels with Defaults○Demo: Seat Ledger Closure Walkthrough○Exercise: Private Budget Ledger✦Module Quiz
○Arrays○Demo: Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Demo: Charging Rack Restock Report○Exercise: Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Map and Set Collections○Playlist Lookup○Number and BigInt Boundaries○Ticket Ledger○JSON○Math and Date○Date Basics○Demo: Supply Bin Audit○Exercise: Volunteer Shift Audit○Demo: Workshop Attendance Feed○Exercise: Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals●Regular Expressions○Demo: Build a Reminder with Template Literals○Exercise: Format Pantry Pickup Messages○Demo: Validate a Time Slot with Regex○Exercise: Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Demo: Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Demo: Handle an Error-First Callback○Exercise: Report Seat Reservation Results○Demo: Summarize Completed Bike Rides○Exercise: Summarize Delivered Parcels✦Module Quiz
○Demo: A notebook object○OOP Introduction○Demo: Independent workshop passes○Classes○Demo: An inherited notice○Inheritance○Demo: A private seat counter○Encapsulation○Demo: Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Demo: Callback Timing○Exercise: Asynchronous JavaScript○Demo: Promise Rehearsal○Exercise: Promises and Async Await○Demo: Offline API Coordination○Exercise: Async API Simulation○Demo: Partial Results Bulletin○Project: Resilient Awards Feed○Demo: Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

Regular Expressions

The next intake step needs to recognize and clean up email-like text. Run script.js and inspect its Console output; regular expressions work on strings, without any page markup.

A regular expression (regex) is a pattern that describes a set of strings. JavaScript has built-in regex support for searching, validating, and transforming strings.

Creating a regex

javascript
// Literal syntax for a fixed pattern
const pattern = /hello/i;   // i = case-insensitive

// The i flag ignores letter case; without it, HELLO does not match /hello/.

Common special characters

PatternMeaning
.Any character except newline (in basic regex mode)
\dDigit (0-9)
\wWord character (letter, digit, _)
\sWhitespace
^Start of string
$End of string
*0 or more
+1 or more
?0 or 1
{n,m}Between n and m
[abc]Character class
[^abc]Negated class

Key methods

javascript
// test() — returns boolean
/^\d{5}$/.test("12345");  // true — zip code
/^\d{5}$/.test("1234");   // false

// match() — returns array of matches
"I have 3 cats and 12 dogs".match(/\d+/g); // ["3", "12"]

// replace() — string substitution
"hello world".replace(/\b\w/g, c => c.toUpperCase()); // "Hello World"

// split() with regex
"one,  two,   three".split(/,\s*/); // ["one", "two", "three"]

Your Task

  1. Complete isValidEmail(email) with the basic shape regex /^[^\s@]+@[^\s@]+\.[^\s@]+$/ and return its boolean result. This checks shape, not deliverability.
  2. Complete extractNumbers(text) to return all digit-sequence strings, or an empty array when none occur.
  3. Complete maskEmail(email) for a valid address with a nonempty local part: retain its first character, replace the rest with *, and keep the domain.
  4. Log one standalone combined line from the three functions: valid: true | numbers: 3,12 | masked: a****@example.com.
Hint 1
1 / 3
HINT 1

Test a pattern: pattern.test(str) returns true/false.

HINT 2

Find matches: str.match(pattern) returns an array or null.

HINT 3

Use flags: g for global, i for case-insensitive.

Loading editor…
Press Run to execute your code.
READY
intercourses
javascript