A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/javascript/RegExp/sticky below:

sticky · WebPlatform Docs

sticky Summary

Returns a Boolean value indicating the state of the sticky flag ( y ) used with a regular expression. Default is false. Read-only.

Syntax
regex.sticky
Examples

The following example illustrates the use of the sticky property.

var regex = /foo.bar/gy;
regex.sticky;

regex.lastIndex;


regex.test('foo*bar');

regex.lastIndex;

regex.test('..foo*bar');


regex.lastIndex = 0;
regex.test('..foo*bar');


regex.lastIndex = 2;
regex.test('..foo*bar');

regex.lastIndex;

Remarks

The sticky property returns true if the sticky flag is set for a regular expression, and returns false if it is not.

The sticky flag, when used, indicates that the regular expression performs sticky matching in the target string by attempting to match starting at lastIndex. If matching at that location fails, then null is returned, i.e., no forward “anchoring” search is performed. If matching succeeds, then the regular expression’s lastIndex property is updated as for the flag g.

See also Other articles

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4