regex 1 character javascript code example

Example 1: javascript regex reference

// Javascript Regex Reference
//  /abc/	A sequence of characters
//  /[abc]/	Any character from a set of characters
//  /[^abc]/	Any character not in a set of characters
//  /[0-9]/	Any character in a range of characters
//  /x+/	One or more occurrences of the pattern x
//  /x+?/	One or more occurrences, nongreedy
//  /x*/	Zero or more occurrences
//  /x?/	Zero or one occurrence
//  /x{2,4}/	Two to four occurrences
//  /(abc)/	A group
//  /a|b|c/	Any one of several patterns
//  /\d/	Any digit character
// /\w/	An alphanumeric character (“word character”)
//  /\s/	Any whitespace character
//  /./	Any character except newlines
//  /\b/	A word boundary
//  /^/	Start of input
//  /$/	End of input

Example 2: javascript regex match character from a set of characters

// Regex - Any character from a set of characters
console.log(/[0123456789]/.test("in 1992")); // true
console.log(/[0-9]/.test("in 1992")); // true
console.log(/[abc]/.test("def")); // false
console.log(/[abc]/.test("cdef")); // true