DEV Community

loading...

Regex - Character Ranges

318097 profile image Mehul Lakhanpal Originally published at codedrops.tech ・1 min read

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

Discussion (0)

pic
Editor guide