Siebel eScript Language Reference > Methods Reference > String Methods >

Get Regular Expression From StringVar Method


The Get Regular Expression From StringVar method searches stringVar for a regular expression. It returns one of the following:

  • If it finds a match, then it returns an array of strings that includes information about each string and the property sets for these strings.
  • If it does not find the regular expression, then it returns the following value:

    Null

Format

stringVar.match(regexp)

Table 38 describes the arguments for the Get Regular Expression From StringVar method.

Table 38. Arguments for the Get Regular Expression From StringVar Method
Argument
Description

regexp

A regular expression that you describe as a literal or as a variable.

Usage without Setting the Global Attribute

If you use the Get Regular Expression From StringVar method with the g global attribute not set on the regular expression, then this usage is the same as with the Get Regular Expression From String method. For more information, see Usage Without Setting the Global Attribute and Get Regular Expression from String Method.

Usage with Setting the Global Attribute

If you use the Get Regular Expression From StringVar method, and if you set the g global attribute on the regular expression, and if this method finds a match, then it does the following:

  • Returns element 0 of the return array as the first text in the string that matches the primary pattern of the regular expression.
  • Returns each subsequent element of the return array as the next text in the string that matches the primary pattern of the regular expression, and that starts after the last character of the previous match. It does not return any matches that overlap other matches.

For example, assume the following is true:

  • The primary pattern of the regular expression is a.. (the letter a followed by any two characters).
  • The string is abacadda.

In this situation the return array includes the following:

  • aba
  • add

It does not include aca.

If you set the g global attribute on the regular expression, then usage for the Get Regular Expression From StringVar method is very different than usage for the Get Regular Expression From String method.

For more information, see Get Regular Expression from String Method.

Example 1

The following example uses the Get Regular Expression From StringVar method with a regular expression whose global attribute is not set:

function fn ()
{
   var myString = new String("Better internet");
   var myRE = new RegExp(/(.).(.er)/i);
   var results = myString.match(myRE);
   var resultmsg = "";
   for(var i =0; i < results.length; i++)
   {
      resultmsg = resultmsg + "return[" + i + "] = " + results[i] + "\n";
   }
   TheApplication().RaiseErrorText(resultmsg);
}
fn ();

This example provides the following output:

return[0] = etter  \\First text that contains primary pattern ...er (any three                    \\characters followed by "er")
return[1] = e       \\First text that matches the first subpattern (.) (any single                    \\character) in the first text that matches the primary pattern
return[2] = ter     \\First text that matches the second subpattern (.er) (any single                     \\character followed by "er") in the first text that matches                     \\the primary pattern

Example 2

The following example uses the Get Regular Expression From StringVar method with a regular expression whose global attribute is set. The method returns matches of the primary pattern of the regular expression that do not overlap:

function fn ()
{
   var str = "ttttot tto";
   var pat = new RegExp("t.t", "g");
   var rtn = str.match(pat);
   var resultmsg = "";
   for(var i =0; i < rtn.length; i++)
   {
      resultmsg = resultmsg + "match [" + i + "] = " + rtn[i] + "\n";
   TheApplication().RaiseErrorText(resultmsg);
   }
}
fn ();

This code produces the following output. This output does not include the ttt instance that starts at position 1 or the t t instance because these instances start in other strings that the Get Regular Expression From StringVar method returns:

match [0] = ttt
match [1] = tot

Siebel eScript Language Reference Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.