JavaScript RegExp +ปริมาณ
ตัวอย่าง 1
ทำการค้นหาทั่วโลกด้วย "o" อย่างน้อยหนึ่งตัว:
let text = "Hellooo World! Hello W3Schools!";
let pattern = /o+/g;
ความหมายและการใช้งาน
n + quantifier ตรงกับสตริงใดๆ ที่มีอย่างน้อยหนึ่งn
ตัวอย่าง 2
ทำการค้นหาทั่วโลกด้วยอักขระอย่างน้อยหนึ่งคำ:
let text = "Hellooo World! Hello W3Schools!";
let pattern = /\w+/g;
รองรับเบราว์เซอร์
/n+/
เป็นคุณลักษณะ ECMAScript1 (ES1)
ES1 (JavaScript 1997) ได้รับการสนับสนุนอย่างสมบูรณ์ในเบราว์เซอร์ทั้งหมด:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
ไวยากรณ์
new RegExp("n+")
or simply:
/n+/
ไวยากรณ์พร้อมตัวแก้ไข
new RegExp("n+", "g")
or simply:
/n+/g