JavaScript เป็น case-sensitive Flag /i (ignore case) ใช้กับ regex replace ทำให้แทนที่คำได้ไม่สนใจตัวพิมพ์เล็ก/ใหญ่
ตัวอย่าง ไม่ใช้ /i (Case-sensitive)
<html> <body> <script>
var str = "Mr Blue has a blue house and a blue car";
var res = str.replace(/blue/g, "red");
document.write(res);
</script> </body> </html>
ผลลัพธ์
Mr Blue has a red house and a red car
"Blue" (ตัวใหญ่) ไม่ถูกแทนที่
ตัวอย่าง ใช้ /i (Ignore case)
<html> <body> <script>
var str = "Mr Blue has a blue house and a blue car";
var res = str.replace(/blue/ig, "red");
document.write(res);
</script> </body> </html>
ผลลัพธ์
Mr red has a red house and a red car
ทุก "Blue"/"blue" ถูกแทนที่ด้วย "red"