const regex = /[a-zA-Z0-9\x{4e00}-\x{9fa5}]+/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('[a-zA-Z0-9\\x{4e00}-\\x{9fa5}]+', 'gm')
const str = `What Does the Fox Say? 12 狐狸怎叫 34
What Does the shiba inu say? 柴犬怎叫
蘋果公司,原稱蘋果電腦公司,是總部位於美國加州庫比蒂諾的跨國科技公司,與亞馬遜,Google、微軟和Meta一起被認為是五大技術公司之一,合稱為MAMAA。
現時的業務包括設計、開發、手機通信和銷售消費電子、電腦軟體、線上服務和個人電腦。`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
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