特定のテキストを検索し、その行に存在するかどうかを確認しようとしています。表示されている場合は「はい」、そうでない場合は「いいえ」と表示されます。現在JS RegExとWhileループの組み合わせ
は私が持っているもの:
const str = `Hello my name is Stack Overlow.`
const publish = /Hello/g;
let pub;
while ((pub = publish.exec(str)) !== null) {
if (pub.index === publish.lastIndex) {
publish.lastIndex++;
}
pub.forEach((ko, groupIndex) => {
document.write(`"Exists": "${ko}",<br>`);
});
}
質問はありません。また、あなたのコードで "はい"と "いいえ"はどこですか? – trincot