String js para regex
const regex = new RegExp('https:\\/\\/\\w*\\.\\w*.*', 'g');
garzj
const regex = new RegExp('https:\\/\\/\\w*\\.\\w*.*', 'g');
const match = 'some/path/123'.match(/\/(\d+)/)
const id = match[1] // '123'
// Tests website Regular Expression against document.location (current page url)
if (/^https\:\/\/example\.com\/$/.exec(document.location)){
console.log("Look mam, I can regex!");
}
function stringToRegex(s, m) {
return (m = s.match(/^([\/~@;%#'])(.*?)\1([gimsuy]*)$/)) ? new RegExp(m[2], m[3].split('').filter((i, p, s) => s.indexOf(i) === p).join('')) : new RegExp(s);
}
console.log(stringToRegex('/(foo)?\/bar/i'));
console.log(stringToRegex('#(foo)?\/bar##gi')); //Custom delimiters
console.log(stringToRegex('#(foo)?\/bar##gig')); //Duplicate flags are filtered out
console.log(stringToRegex('/(foo)?\/bar')); // Treated as string
console.log(stringToRegex('gig')); // Treated as string
Run code snippetHide results