-1
正規表現は初めてです。誰かを指し示すか、またはプロトコルチェックなしで正規表現ドメイン名(so-mysite.comなど)またはURLバリデーター正規表現を検証する正規表現を提案できますか?FQDN/URL形式バリデーター正規表現の正規表現2
正規表現は初めてです。誰かを指し示すか、またはプロトコルチェックなしで正規表現ドメイン名(so-mysite.comなど)またはURLバリデーター正規表現を検証する正規表現を提案できますか?FQDN/URL形式バリデーター正規表現の正規表現2
これは動作するはずです:
正規表現:
/^([a-z0-9-]+\.[a-z0-9]{2,}$)/gm
入力:
mysite.com
test.net
testing.-com
camels.com.net
出力:
mysite.com
test.net
JavaScriptのコード:
const regex = /^([a-z0-9-]+\.[a-z0-9]{2,}$)/gm;
const str = `mysite.com
test.net
testing.-com
camels.com.net`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
参照してください:https://regex101.com/r/ncVEAT/3
/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/