首页 > 编程语言 > 详细

JavaScript正则表达式-后缀选项(标记)

时间:2014-12-23 22:36:24      阅读:178      评论:0      收藏:0      [点我收藏+]

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 "]

JavaScript正则表达式-后缀选项(标记)

原文:http://www.cnblogs.com/snzigod/p/4181216.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!