Bookshelf Home | Contents | Index | PDF |
Siebel eScript Language Reference > Siebel eScript Commands > RegExp Object MethodsThe Siebel ST eScript engine does not support the following static methods of the RegExp object: RegExp.$n (including '$_' and '$&'), RegExp.input, RegExp.lastMatch, RegExp.lastParen, RegExp.leftContext, and RegExp.rightContext. The Siebel T engine does support these methods. Both the Siebel ST and T eScript engines support the following methods that are documented in this section: Throughout this section, regexp is used to represent a RegExp object instance. RegExp compile() MethodThis method changes the pattern and attributes to use with the current instance of a RegExp object. Syntaxregexp.compile(pattern[, attributes]) UsageThis method allows use of a RegExp instance multiple times with changes to its characteristics. Use the compile() method with a regular expression that is created with the constructor function, not the literal notation. Examplevar regobj = new RegExp("now"); See alsoRegExp exec() MethodThis method returns an array of strings that are matches of the regular expression on the target string. SyntaxReturnsThis method returns an array with various elements (the matched strings that are found), and their property sets. The elements returned depend on the attributes of the regular expression. The method returns null if no match is found. UsageOf all the RegExp and String methods, RegExp exec() is one of the most powerful because it includes all information about each match in its returned array. When exec() is executed without the global attribute, "g", being set on the RegExp instance, and a match is found, then:
These elements and their numbers correspond to groups in regular expression patterns and replacement expressions. The returned array includes the following properties:
The return values, and the index and input properties are the same as those of the returned array from the String match() Method when match() is used on a regular expression whose global attribute is not set. When exec() is executed with the global attribute, "g", set on the RegExp instance, and a match is found, then:
If you use the T eScript engine and any matches are found, appropriate RegExp object static properties, such as RegExp.leftContext, RegExp.rightContext, RegExp.$n, and so forth are set, providing more information about the matches. NOTE: The ST eScript engine does not support the following static properties of the RegExp object: RegExp.$n (including '$_' and '$&'), RegExp.input, RegExp.lastMatch, RegExp.lastParen, RegExp.leftContext, RegExp.rightContext. ExamplesThe following example calls exec() from a regular expression whose global attribute is not set. The output is commented. function fn () return[0] = etter \\First text containing primary pattern ...er (any three \\characters followed by "er") The following example calls exec() from a regular expression whose global attribute is set. The method returns all matches of the regular expression's primary pattern in a string, including matches that overlap. function fn () Text = ttt Pos = 0 End = 2 See alsoRegExp test() MethodThis method indicates whether a target string contains a regular expression pattern. SyntaxReturnsThis method returns true if the target string contains the regular expression pattern, else it returns false. UsageThis method is equivalent to regexp.exec(str)!=null. If you use the T eScript engine and there is a match, then appropriate RegExp object static properties, such as RegExp.leftContext, RegExp.rightContext, RegExp.$n, and so forth are set, providing more information about the matches. NOTE: The ST eScript engine does not support the following static properties of the RegExp object: RegExp.$n (including '$_' and '$&'), RegExp.input, RegExp.lastMatch, RegExp.lastParen, RegExp.leftContext, RegExp.rightContext. Although not common, test() may be used in a special way when the global attribute, "g", is set on the RegExp instance. As with RegExp exec(), when a match is found, the lastIndex property of the RegExp instance is set to the character position after the found text match. Thus, test() may be used repeatedly on a string, for instance, to determine whether a string has more than one match or to count the number of matches. For information about using the RegExp lastIndex property repeatedly on a string, see RegExp exec() Method. Examplevar str = "one two three tio one"; See also |
Siebel eScript Language Reference |