标签:高级语言 示例 regexp source .com pre class regex log
var str = "iid0000ffr";
var substr = str.match(/id(\S*)ff/);
console.log(substr)
返回结果为:["id0000ff", "0000"]
()里的\S*表达式匹配所有字符串
在高级语言里,我们会用一个叫数量词的概念:
var str = "iid0000ffr";
var substr = str.match(/(\S*)(?=ff)/);
console.log(substr)
返回数组:["iid0000", "iid0000"]
var str = "iid0000ffr";
var substr = str.match(/(iid=?)(\S*)/);
console.log(substr);
返回数组:["iid0000ffr", "iid", "0000ffr"]
跟第一个示例一样获取前后中间的字符串
var str = "iid0000ffr";
var substr = str.match(/(iid=?)(\S*)(?=ffr)/);
console.log(substr);
返回数组:["iid0000", "iid", "0000"]
原文地址http://www.cnblogs.com/dtdxrk/p/4601890.html
标签:高级语言 示例 regexp source .com pre class regex log
原文地址:http://www.cnblogs.com/garfieldzhong/p/6100324.html