Ranges help in matching characters by specifying start and end characters.
// Ranges are specified in [].
// Range specifies to match numbers & alphabets only from a to f
const colorRegex = /[0-9a-f]{6}/gi;
const colorCode1 = "#abc324";
console.log(colorCode1.match(colorRegex)); // ['abc324']
const colorCode2 = "#asc324";
console.log(colorCode2.match(colorRegex)); // null
Thanks for reading π
Follow @codedrops.tech for daily posts.
Instagram β Twitter β Facebook
Micro-Learning β Web Development β Javascript β MERN stack β Javascript
codedrops.tech
Top comments (0)