const regex = /nurhuda/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('nurhuda', 'gm')
const str = `<script type="text/javascript">
function validasi_input(form){
pola_username=/^[a-z]{5,7}\$/;
if (!pola_username.test(form.username.value)){
alert ('Username minimal 5-7 karakter dan hanya boleh Huruf kecil!');
form.username.focus();
return false;
}
return (true);
}
function password(nilai, pesan) {
var pass = /^([a-zA-Z0-9_.+-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{9})+\$/;
if(nilai.value.match(pass)) {
return true;
}
else {
alert(password merupakan kombinasi huruf kecil, huruf besar, angka dan simbol "@" dan harus 9 karakter);
nilai.focus();
return false;
}
}
</script>`;
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}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions