例子
代码如下 | 复制代码 |
/* * 获取两个字符串之间的字符,获取最近配对的两个字符串之间的字符串 * s: 要截取的字符串 * b: 两个字符串默认为'()'或'["(", ")"]', * r: 返回数组类型 * getbsVal(s, "()"); 调用方法 */ function getbsVal(s, b){ b = b ? b : "()"; var r = []; s = s.split(b[0]).slice(1); for(var i in s) { if (new RegExp("\" + b[1]).test(s[i])) { r.push(s[i].split(b[1])[0]); } } return r; } |
例子
代码如下 | 复制代码 |
var dirs = ["a", "b", "c", "d", "e"]; var ignores = ["c", "e"], iglen = ignores.length; for (var ig = 0; ig < iglen; ig++) { var sReg = new RegExp("^" + ignores[ig] + ",|," + ignores[ig] + "(?=,)|," + ignores[ig] + "$", "g"); dirs = dirs.join(",").replace(sReg, "").split(","); } // dirs = ["a", "b", "d"] |
vbs的一种写法
代码如下 | 复制代码 |
'得到两个字符串中间的字符串。 '例如:
'text="人民币300元",tBefore="人民币",tAfter="元"
'使用between(text,tBefore,tAfter)得到300. Public Function between(words,wordBefore,wordAfter)
t1=InStr(words,wordBefore) If t1=0 Then //www.111cn.net between=words
Else L1=Len(wordBefore) wordsRight=Right(words,Len(words)-t1-L1+1)
t2=InStr(wordsRight,wordAfter) If t2=0 Then wordAfter=""
End If If wordAfter="" Then t2=Len(wordsRight)+1 Else t2=InStr(wordsRight,wordAfter) End If needWord=Left(wordsRight,t2-1) ' needWord=Mid(words,t1+L1,t2-t1-L1) between=needWord
End If End Function |
时间: 2024-10-12 14:17:17