👌
JavaScriptのURLとマッチする正規表現
const pattern = /^https?:\/\/[\w/:%#\$&\?\(\)~\.=\+\-]+$/
const result1 = pattern.test('https://zenn.dev/purratto?page=1')
console.log(result1) // true
const result2 = pattern.test('zenn')
console.log(result2) // false
const pattern = /^https?:\/\/[\w/:%#\$&\?\(\)~\.=\+\-]+$/
const result1 = pattern.test('https://zenn.dev/purratto?page=1')
console.log(result1) // true
const result2 = pattern.test('zenn')
console.log(result2) // false
Discussion