JavaScript RegExp m 修饰符

定义和用法

"m" 修饰符规定多行匹配。

It only affects the beginning. ^ and the end. $ behavior.

^ matches the beginning of the string.

$ matches the end of the string.

After setting "m",^ and $ Also matches the beginning and end of each line.

Example

Search for "is" multiline at the beginning of each line in the string:

let text = `Is this
all there
is`
let pattern = /^is/m;

ကျွန်တော် ကျင်းပ

Tip 1

"m" modifier is case-sensitive rather than global.

To perform a global and case-insensitive search, use "m" with "g" and "i" together.

Example 1

Search globally multiline for "is" at the beginning of each string line:

let text = `Is this
all there
is`
let pattern = /^is/gm;

ကျွန်တော် ကျင်းပ

Example 2

Search globally and case-insensitive multiline for "is" at the beginning of each string line:

let text = `Is this
all there
is`
let pattern = /^is/gmi;

ကျွန်တော် ကျင်းပ

Example 3

Search globally multiline for "is" at the end of each string line:

let text = `Is this
all there
is`
let text = "Is\nthis\nhis\n?";
let pattern = /is$/gm;

ကျွန်တော် ကျင်းပ

အကြိမ် 2

အသုံးပြုနိုင် multiline သတ်မှတ်ခြင်း မရှိဘဲ m ပြောင်းလဲသည်

Check if the "m" modifier is set:
let pattern = /W3S/gi;
let result = pattern.multiline;

ကျွန်တော် ကျင်းပ

အက္ခရာ

new RegExp("regexp", "m")

ပြောင်းလဲသည်:

/regexp/m

ဘာသာစကားပြောင်းလဲသည်

/regexp/m ECMAScript3 (ES3) သဘောတူ ဖြစ်သည်

အားလုံး ဘာသာစကား ဘာသာစကားပြောင်းလဲသည် (JavaScript 1999) အား လက်ခံကြသည်:

Chrome IE Edge Firefox Safari Opera
လက်ခံ လက်ခံ လက်ခံ လက်ခံ လက်ခံ လက်ခံ

နည်းလမ်း

JavaScript တွင် အသုံးပြုသော နည်းလမ်းများ အသုံးပြုနိုင်သည့် အချက်အလက် များ အချို့ အပြီးအမြစ် ဖြစ်ပါတယ်。

အသုံးပြုပုံစံသဘောတူ အသုံးပြုသော နည်းလမ်းများမှာ အသုံးများစွာ ဖြစ်ကြသည့် အသုံးပြုနိုင်သော နည်းလမ်းများ ဖြစ်ပါတယ်:

အမှတ်အသား သက်သေ
text.match(ပုံစံ) စကားလုံး နည်းလမ်း match()
text.search(ပုံစံ) စကားလုံး နည်းလမ်း search()
ပုံစံ.exec(text) RexExp နည်းလမ်း exec()
ပုံစံ.test(text) RexExp နည်းလမ်း test()