码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2014-12-23 22:36:27      阅读:264      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!