regex symbols javascript code example
Example 1: regex special characters javascript
var regex = /^[a-zA-Z0-9!@#\$%\^\&*\)\(+=._-]+$/g
Example 2: regular expression javascript
// Tests website Regular Expression against document.location (current page url)
if (/^https\:\/\/example\.com\/$/.exec(document.location)){
console.log("Look mam, I can regex!");
}
Example 3: 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