React Native: <string> .matchAll ไม่ใช่ฟังก์ชัน
Nov 20 2020
ฉันได้รับข้อผิดพลาดแปลก ๆ เมื่อเรียกใช้แอป React Native:
โค้ดตัวอย่างบางส่วน:
const { url } = <incoming object>;
const reURL = <my regex>;
console.debug('url:', url);
console.debug('typeof url:', typeof url);
matches = [...url.matchAll(reURL)];
เอาต์พุตบันทึก:
url: <as expected>
typeof url: string
ข้อความผิดพลาด:
TypeError: url.matchAll is not a function. (In 'url.matchAll(reURL)', 'url.matchAll' is undefined)
ทุกอย่างทำงานได้ดีบน iOS ข้อผิดพลาดเกิดขึ้นบน Android เท่านั้น
สภาพแวดล้อมnpmค่อนข้างทันสมัยอัปเดตแพ็คเกจทั้งหมดเมื่อสองสามวันก่อน
ใครมีความคิดเล็กน้อยที่สุดว่าจะเริ่มค้นหาวิธีแก้ปัญหาได้จากที่ไหน?
คำตอบ
NguyễnThịThúy Nov 27 2020 at 08:17
ฉันมีปัญหาเดียวกัน String.matchAllไม่ทำงานสำหรับ Android คุณควรใช้แทนmatchmatchAll
ตัวอย่าง:
const regex = new RegExp(text, 'ig');
const arr = string.match(regex);
คุณจะได้รับ regex การจับคู่อาร์เรย์