6 Star 10 Fork 0

Gitee 极速下载/dojo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/dojo/dojo
克隆/下载
regexp.js 2.00 KB
一键复制 编辑 原始数据 按行查看 历史
define(["./_base/kernel", "./_base/lang"], function(dojo, lang){
// module:
// dojo/regexp
var regexp = {
// summary:
// Regular expressions and Builder resources
};
lang.setObject("dojo.regexp", regexp);
regexp.escapeString = function(/*String*/str, /*String?*/except){
// summary:
// Adds escape sequences for special characters in regular expressions
// except:
// a String with special characters to be left unescaped
return str.replace(/([\.$?*|{}\(\)\[\]\\\/\+\-^])/g, function(ch){
if(except && except.indexOf(ch) != -1){
return ch;
}
return "\\" + ch;
}); // String
};
regexp.buildGroupRE = function(/*Object|Array*/arr, /*Function*/re, /*Boolean?*/nonCapture){
// summary:
// Builds a regular expression that groups subexpressions
// description:
// A utility function used by some of the RE generators. The
// subexpressions are constructed by the function, re, in the second
// parameter. re builds one subexpression for each elem in the array
// a, in the first parameter. Returns a string for a regular
// expression that groups all the subexpressions.
// arr:
// A single value or an array of values.
// re:
// A function. Takes one parameter and converts it to a regular
// expression.
// nonCapture:
// If true, uses non-capturing match, otherwise matches are retained
// by regular expression. Defaults to false
// case 1: a is a single value.
if(!(arr instanceof Array)){
return re(arr); // String
}
// case 2: a is an array
var b = [];
for(var i = 0; i < arr.length; i++){
// convert each elem to a RE
b.push(re(arr[i]));
}
// join the REs as alternatives in a RE group.
return regexp.group(b.join("|"), nonCapture); // String
};
regexp.group = function(/*String*/expression, /*Boolean?*/nonCapture){
// summary:
// adds group match to expression
// nonCapture:
// If true, uses non-capturing match, otherwise matches are retained
// by regular expression.
return "(" + (nonCapture ? "?:":"") + expression + ")"; // String
};
return regexp;
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/dojo.git
git@gitee.com:mirrors/dojo.git
mirrors
dojo
dojo
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385