DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

Regex - Character Ranges

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
Enter fullscreen mode Exit fullscreen mode

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)