SlideShare a Scribd company logo
REGEX CHEATSHEET
Part 2
CHEAT SHEET
Extracting first match:
Using the match() function
const match = "Hello World!".match(/hello/i);
// "Hello"
Extracting all matches:
Using the g flag
const testString = "Repeat repeat rePeAT";
const regexWithAllMatches = /Repeat/gi;
testString.match(regexWithAllMatches);
// ["Repeat", "repeat", "rePeAT"]
Matching single character with multiple
possibilities:
// Match "cat" "fat" and "mat" but not "bat"
const regexWithCharClass = /[cfm]at/g;
const testString = "cat fat bat mat";
const allMatchingWords =
testString.match(regexWithCharClass);
// ["cat", "fat", "mat"]
Match a single, unknown character:
● To match a set of characters you don't want to
have, use the negated character set
● To negate a character set, use a caret ^
const allCharsNotVowels = /[^aeiou]/gi;
const allCharsNotVowelsOrNumbers =
/[^aeiou0-9]/gi;
const regexWithCharRange = /[a-e]at/;
const catString = "cat";
const batString = "bat";
const fatString = "fat";
regexWithCharRange.test(catString); // true
regexWithCharRange.test(batString); // true
regexWithCharRange.test(fatString); // false
Match letter of the alphabet:
Using range within the character range [a-z]

More Related Content

More from Ideas2IT Technologies (20)

PDF
Json.parse() in JavaScript
Ideas2IT Technologies
 
PDF
Bubble sort in Java Script
Ideas2IT Technologies
 
PDF
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
PDF
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
PDF
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
PDF
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
PDF
Variable hoisting in JavaScript
Ideas2IT Technologies
 
PDF
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
PDF
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-2
Ideas2IT Technologies
 
PDF
Logging in JavaScript - part-1
Ideas2IT Technologies
 
PDF
Array vs set in JavaScript
Ideas2IT Technologies
 
PDF
Arguments Object in JavaScript
Ideas2IT Technologies
 
PDF
Pollyfills in JavaScript
Ideas2IT Technologies
 
PDF
Async await in JavaScript - part-3
Ideas2IT Technologies
 
PDF
Async await in JavaScript
Ideas2IT Technologies
 
PDF
Regex cheatsheet part-1
Ideas2IT Technologies
 
PDF
Difference between promise-chain and promise.all() in Javascript
Ideas2IT Technologies
 
Json.parse() in JavaScript
Ideas2IT Technologies
 
Bubble sort in Java Script
Ideas2IT Technologies
 
Performance analysis in merging arrays - JavaScript
Ideas2IT Technologies
 
Nullish coalescing in JavaScript
Ideas2IT Technologies
 
Conditionally add keys in JavaScript
Ideas2IT Technologies
 
What is Big O in JavaScript - Part-1
Ideas2IT Technologies
 
Variable hoisting in JavaScript
Ideas2IT Technologies
 
Formidable ES6 spread operator in JavaScript
Ideas2IT Technologies
 
Logging in JavaScript - Part-5
Ideas2IT Technologies
 
Logging in JavaScript - Part-4
Ideas2IT Technologies
 
Logging in JavaScript - Part-3
Ideas2IT Technologies
 
Logging in JavaScript - part-2
Ideas2IT Technologies
 
Logging in JavaScript - part-1
Ideas2IT Technologies
 
Array vs set in JavaScript
Ideas2IT Technologies
 
Arguments Object in JavaScript
Ideas2IT Technologies
 
Pollyfills in JavaScript
Ideas2IT Technologies
 
Async await in JavaScript - part-3
Ideas2IT Technologies
 
Async await in JavaScript
Ideas2IT Technologies
 
Regex cheatsheet part-1
Ideas2IT Technologies
 
Difference between promise-chain and promise.all() in Javascript
Ideas2IT Technologies
 

Recently uploaded (20)

PPTX
ManageIQ - Sprint 265 Review - Slide Deck
ManageIQ
 
PPTX
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
PDF
Rewards and Recognition (2).pdf
ethan Talor
 
PPTX
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
PPTX
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
PDF
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
PDF
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
PDF
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
 
PPTX
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
PPTX
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PPTX
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
PDF
Dealing with JSON in the relational world
Andres Almiray
 
PDF
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
 
PDF
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
PDF
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
PPTX
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
PPTX
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
ManageIQ - Sprint 265 Review - Slide Deck
ManageIQ
 
Cubase Pro Crack 2025 – Free Download Full Version with Activation Key
HyperPc soft
 
Rewards and Recognition (2).pdf
ethan Talor
 
Mistakes to Avoid When Selecting Policy Management Software
Insurance Tech Services
 
ERP - FICO Presentation BY BSL BOKARO STEEL LIMITED.pptx
ravisranjan
 
WholeClear Split vCard Software for Split large vCard file
markwillsonmw004
 
Laboratory Workflows Digitalized and live in 90 days with Scifeon´s SAPPA P...
info969686
 
The Rise of Sustainable Mobile App Solutions by New York Development Firms
ostechnologies16
 
Automatic_Iperf_Log_Result_Excel_visual_v2.pptx
Chen-Chih Lee
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
IObit Driver Booster Pro 12.4-12.5 license keys 2025-2026
chaudhryakashoo065
 
Quality on Autopilot: Scaling Testing in Uyuni
Oscar Barrios Torrero
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
ManageIQ - Sprint 264 Review - Slide Deck
ManageIQ
 
Dealing with JSON in the relational world
Andres Almiray
 
IDM Crack with Internet Download Manager 6.42 Build 41
utfefguu
 
Code Once; Run Everywhere - A Beginner’s Journey with React Native
Hasitha Walpola
 
From Chaos to Clarity: Mastering Analytics Governance in the Modern Enterprise
Wiiisdom
 
EO4EU Ocean Monitoring: Maritime Weather Routing Optimsation Use Case
EO4EU
 
WYSIWYG Web Builder Crack 2025 – Free Download Full Version with License Key
HyperPc soft
 
Ad

Regex Cheat Sheet in JavaScript - part-2

  • 2. CHEAT SHEET Extracting first match: Using the match() function const match = "Hello World!".match(/hello/i); // "Hello" Extracting all matches: Using the g flag const testString = "Repeat repeat rePeAT"; const regexWithAllMatches = /Repeat/gi; testString.match(regexWithAllMatches); // ["Repeat", "repeat", "rePeAT"]
  • 3. Matching single character with multiple possibilities: // Match "cat" "fat" and "mat" but not "bat" const regexWithCharClass = /[cfm]at/g; const testString = "cat fat bat mat"; const allMatchingWords = testString.match(regexWithCharClass); // ["cat", "fat", "mat"] Match a single, unknown character: ● To match a set of characters you don't want to have, use the negated character set ● To negate a character set, use a caret ^ const allCharsNotVowels = /[^aeiou]/gi; const allCharsNotVowelsOrNumbers = /[^aeiou0-9]/gi;
  • 4. const regexWithCharRange = /[a-e]at/; const catString = "cat"; const batString = "bat"; const fatString = "fat"; regexWithCharRange.test(catString); // true regexWithCharRange.test(batString); // true regexWithCharRange.test(fatString); // false Match letter of the alphabet: Using range within the character range [a-z]