js regex expression code example
Example 1: javascript regex
let reg = /abc/
reg = new RegExp('abc')
let str = 'Abc abc abc'
str.match(/abc/)
str.match(/abc/g)
str.match(/abc/i)
str.match(/abc/ig)
str.match('abc', 'ig')
Example 2: js string to regex
const regex = new RegExp('https:\\/\\/\\w*\\.\\w*.*', 'g');
Example 3: regular expression javascript
if (/^https\:\/\/example\.com\/$/.exec(document.location)){
console.log("Look mam, I can regex!");
}
Example 4: javascript regex match sequence
console.log(/abc/.test("abcde"));
console.log(/abc/.test("abxde"));