JavaScript RegExp exec()
ဥပမာ
စာလုံး "e" အတွက် စာကြောင်းကို ရှာပါ-
let text = "The best things in life are free";
let result = /e/.exec(text);
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
exec() method သည် string တစ်ခုရှိ ကိုက်ညီမှုအတွက် စမ်းသပ်သည်။
ကိုက်ညီမှုတစ်ခုတွေ့ပါက၊ ၎င်းသည် ရလဒ် array ကိုပြန်ပေးသည်၊ သို့မဟုတ်ပါက ၎င်းသည် null ဖြစ်သွားသည်။
Browser ပံ့ပိုးမှု
exec()
ECMAScript1 (ES1) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ES1 (JavaScript 1997) ကို ဘရောက်ဆာအားလုံးတွင် အပြည့်အဝ ပံ့ပိုးထားသည်။
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
အထားအသို
RegExpObject.exec(string)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
string | Required. The string to be searched |
တန်ဖိုးကို ပြန်ပေးသည်။
Type | Description |
---|---|
Array | An array containing the matched text if it finds a match, otherwise it returns null |
နောက်ထပ် ဥပမာများ
ဥပမာ
"Hello" နှင့် "W3Schools" အတွက် ကမ္ဘာလုံးဆိုင်ရာ ရှာဖွေမှုကို string တစ်ခုဖြင့် ပြုလုပ်ပါ-
let text = "Hello world!";
// Look for "Hello"
let result1 = /Hello/.exec(text);
// Look for "W3Schools"
let result2 = /W3Schools/.exec(text);
ပုံမှန်ဖော်ပြမှုရှာဖွေရေးနည်းလမ်းများ
JavaScript တွင်၊ ပုံမှန် expression text search ကို မတူညီသောနည်းလမ်းများဖြင့် လုပ်ဆောင်နိုင်သည်။
ပုံမှန်အသုံးအနှုန်းအဖြစ် ပုံစံ တစ်ခု ဖြင့်၊ ဤအရာများသည် အသုံးအများဆုံးနည်းလမ်းများဖြစ်သည်-
ဥပမာ | ဖော်ပြချက် |
---|---|
text.match( ပုံစံ ) | String method သည် match() |
text.search( ပုံစံ ) | စာတန်းနည်းလမ်းရှာဖွေမှု() |
ပုံစံ .exec(စာသား) | RexExp နည်းလမ်း exec() |
ပုံစံ .test(စာသား) | RegExp နည်းလမ်းစမ်းသပ်မှု() |