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)