matchAll Method
matchAll method သည်
regular expression
နှင့် ကိုက်ညီသော အရာအားလုံးကို
iterable object
အဖြစ် ပြန်ပေးပြီး ၎င်း၏ element တစ်ခုစီသည်
တွေ့ရှိခဲ့သည့် အရာ နှင့် ၎င်း၏ capturing groups များပါဝင်သော array ကို ပါဝင်ပါသည်။
Method ကို g modifier ဖြင့်သာ အသုံးပြုနိုင်ပါသည်။
ကိုက်ညီမှုမရှိပါက null ပြန်ပေးမည်။
Syntax
string.matchAll(regular expression);
ဥပမာ
ကိုက်ညီမှုအားလုံးကို ရယူပြီး loop ဖြင့် ထပ်ကျော့ကြည့်ကြပါစို့:
let str = '12 34 56';
let matches = str.matchAll(/(\d)(\d)/g);
for (let match of matches) {
console.log(match);
}
Code ကို run လိုက်သော အခါ ရလဒ်:
[12, 1, 2]
[34, 3, 4]
[56, 5, 6]
ဥပမာ
Iterable object ကို ပုံမှန် array အဖြစ်သို့ ပြောင်းလဲကြည့်ကြပါစို့:
let str = '12 34 56';
let matches = str.matchAll(/(\d)(\d)/g);
let res = Array.from(matches);
console.log(res);
Code ကို run လိုက်သော အခါ ရလဒ်:
[
[12, 1, 2],
[34, 3, 4],
[56, 5, 6]
]
ဆက်လက်လေ့လာရန်
-
testmethod,
သည် string ကို စစ်ဆေးပေးသည် -
matchmethod,
သည် string ထဲတွင် ကိုက်ညီမှုကို ရှာဖွေပေးသည် -
execmethod,
သည် အစဉ်လိုက် ရှာဖွေမှု ပြုလုပ်ပေးသည် -
replacemethod,
သည် ရှာဖွေခြင်း နှင့် အစားထိုးခြင်းကို ပြုလုပ်ပေးသည် -
searchmethod,
သည် ရှာဖွေမှုကို ပြုလုပ်ပေးသည် -
splitmethod,
သည် string ကို ပိုင်းခြားပေးသည်