const regex = /(?:單([^\d\$])+)/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('(?:單([^\\d\\$])+)', 'gm')
const str = `10:11く⑥你的萬寧官方網店訂單已確認 - 2105351889く萬寧 mannings你的訂單已確認 -2105351889Ruby Wong 你好,感謝你於萬寧官方網店購物。我們會盡快處理你的訂單,以下是你的訂單詳情:訂單編號2105351889訂購日期2024年6月3日收貨地址:香港九龍紅磡高山道9號恒山閣4樓 403室送貨詳情:訂單狀態:訂單處理中預計送貨日期:2-5個工作天(以收到短訊/電郵日期為準)[請留意]所有送貨日期和時間均為預計的。當閣下的訂單和送貨獲得確認後,閣下將會收到我們有關實際送貨安排的事先通知。萬寧將保留因應實際貨存而修改訂單內容之權利。產品售價Abbotf雅培金装加營素方便即飲裝雲呢拿味\$518.00(原箱)250毫升×24罐171496數量4金額\$1,761.20金裝加營素即飲裝原箱85折運費:訂單總額:vuu ID:免費\$1,761.20
`;
// 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