Patterns and Flags:

Matches all occurrences of the pattern.

JavaScript
let text = "The cat is on the mat. Another cat is in the hat.";
let regex = /cat/g;
let result = text.match(regex);
console.log(result); // Output: ["cat", "cat"]

Ignores case.

JavaScript
let text = "Dog days are here. DOGS are wonderful.";
let regex = /dog/i;
let result = text.match(regex);
console.log(result); // Output: ["Dog"]

Treats the string as multiple lines.

JavaScript
let text = `Hello world
Welcome to JavaScript
Learning is fun`;
let regex = /^Welcome/m;
let result = text.match(regex);
console.log(result); // Output: ["Welcome"]

Makes . match newline characters.

JavaScript
let text = `Dear User,
Thank you for signing up.
We hope you enjoy your experience.

Best Regards,
The Team`;

let regex = /Dear User.*experience/s; // Matches everything from "Dear User" to "experience"
let result = text.match(regex);
console.log(result); 
// Output: ["Dear User,\nThank you for signing up.\nWe hope you enjoy your experience"]
JavaScript
let emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
let email = "test@example.com";
console.log(emailRegex.test(email)); // true
JavaScript
let text = "There are 3 apples and 7 bananas.";
let regex = /\d+/g; // Matches all numbers globally
console.log(text.match(regex)); // Output: ["3", "7"]