JavaScript正则表达式-后缀选项(标记)
i:表示匹配时不区分大小写
Str = "JavaScript is different from java";
reg = /java\w*/i;
arr_m = str.match(reg);//arr_m = ["JavaScript"]
g:表示执行全局匹配
Str = "JavaScript is different from java";
reg = /java\w*/ig;
arr_m = str.match(reg);//arr_m = ["JavaScript"]
m:表示采用多行模式执行匹配
在多行模式时,^表示一行的开头或者字符串的开头,$表示一行的结尾(换行)或者字符串的结尾
str = "JavaScript is different from java They are different";
reg = /\w+$/;
arr_m = str.match(reg);//arr_m = ["different"]
str = "JavaScript is different from java\nThey are different";
reg = /\w+$/;
arr_m = str.match(reg);//arr_m = ["different"]
str = "JavaScript is different from java\nThey are different";
reg = /\w+$/mg;
arr_m = str.match(reg);//arr_m = ["java","different"]
str = "JavaScript is different from java\njavascript and java are different.";
reg1 = /(^java\w*)|(java)/ig;
reg2 = /(^java\w*)|(java)/img;
arr_m1 = str.match(reg);//arr_m1 = ["JavaScript"]
arr_m2 = str.match(reg);//arr_m2 = ["JavaScript","java","javascript "]