1 if(!dojo._hasResource["dojo.regexp"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["dojo.regexp"] = true;
3 dojo.provide("dojo.regexp");
7 // summary: Regular expressions and Builder resources
11 dojo.regexp.escapeString = function(/*String*/str, /*String?*/except){
13 // Adds escape sequences for special characters in regular expressions
15 // a String with special characters to be left unescaped
17 // return str.replace(/([\f\b\n\t\r[\^$|?*+(){}])/gm, "\\$1"); // string
18 return str.replace(/([\.$?*!=:|{}\(\)\[\]\\\/^])/g, function(ch){
19 if(except && except.indexOf(ch) != -1){
26 dojo.regexp.buildGroupRE = function(/*Object|Array*/arr, /*Function*/re, /*Boolean?*/nonCapture){
28 // Builds a regular expression that groups subexpressions
30 // A utility function used by some of the RE generators. The
31 // subexpressions are constructed by the function, re, in the second
32 // parameter. re builds one subexpression for each elem in the array
33 // a, in the first parameter. Returns a string for a regular
34 // expression that groups all the subexpressions.
36 // A single value or an array of values.
38 // A function. Takes one parameter and converts it to a regular
41 // If true, uses non-capturing match, otherwise matches are retained
42 // by regular expression. Defaults to false
44 // case 1: a is a single value.
45 if(!(arr instanceof Array)){
46 return re(arr); // String
49 // case 2: a is an array
51 for(var i = 0; i < arr.length; i++){
52 // convert each elem to a RE
56 // join the REs as alternatives in a RE group.
57 return dojo.regexp.group(b.join("|"), nonCapture); // String
60 dojo.regexp.group = function(/*String*/expression, /*Boolean?*/nonCapture){
62 // adds group match to expression
64 // If true, uses non-capturing match, otherwise matches are retained
65 // by regular expression.
66 return "(" + (nonCapture ? "?:":"") + expression + ")"; // String