Share via


index Property (JScript 5.6) 

Returns the character position where the first successful match begins in a searched string. Read-only.


RegExp.index 

Remarks

The object associated with this property is always the global RegExp object.

The index property is zero-based. The initial value of the index property is –1. Its value changes whenever a successful match is made.

Example

The following example illustrates the use of the index property. This function iterates a search string and prints out the index and lastIndex values for each word in the string.

function RegExpTest(){

  var ver = Number(ScriptEngineMajorVersion() + "." + ScriptEngineMinorVersion())

  if (ver >= 5.5){

    var src = "The rain in Spain falls mainly in the plain.";

    var re = /\w+/g;

    var arr;

    while ((arr = re.exec(src)) != null)

       print(arr.index + "-" + arr.lastIndex + "\t" + arr);

  }

  else{

    alert("You need a newer version of JScript for this to work");

  }

}

Requirements

Version 3

Applies To: RegExp Object (JScript 5.6)

See Also

Reference

Regular Expression Syntax (Scripting)