Javascript Regex LastIndex Properties

JavaScript LastIndex property helps to return the last index of the match string. We can get the regular expression pattern to match and get the last position before starting the next value. It helps with long string and array values operation and filter. The exec and test method resets the "0" value if the string does not match.

Syntax

The following syntax is used to get the last index before starting the next value.

Supported Browsers

The browsers supported by RegExp's last index properties are given below:

  • Google Chrome
  • Edge
  • Firefox
  • Internet Explorer
  • Opera
  • Safari

Examples

The following examples are the last position of the matching string.

Example 1:

The example shows the last position of the match character for the lastIndex property. Here, we use regex directly with the lastIndex keyword.

Output

The output shows the last index position of the matching string.

Javascript Regex LastIndex Properties

Example 2:

The example shows the array function's last position of the matching character for the lastIndex property.

Output

The output shows the last index position of the matching string.

Javascript Regex LastIndex Properties

Example 3:

The example shows the string's last position of the match character for the lastIndex property.

Output

The output shows the last index position of the matching string.

Javascript Regex LastIndex Properties

Example 4:

The example shows the number function at the last position of the matching character for the lastIndex property.

Output

The output shows the last index position of the matching string.

Javascript Regex LastIndex Properties

Conclusion

The regex lastIndex property shows the last position of the matching string before the following characters.






Latest Courses