A RetroSearch Logo

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

Search Query:

Showing content from https://www.npmjs.com/package/regexp-match-indices below:

regexp-match-indices - npm

regexp-match-indices

This package provides a polyfill/shim for the RegExp Match Indices proposal.

The implementation is a replacement for RegExp.prototype.exec that approximates the beahvior of the proposal. Because RegExp.prototype.exec depends on a receiver (the this value), the main export accepts the RegExp to operate on as the first argument.

Installation

npm install regexp-match-indices

Usage Standalone

const execWithIndices = require("regexp-match-indices");

 

const text = "zabbcdef";

const re = new RegExp("ab*(cd(?<Z>ef)?)");

const result = execWithIndices(re, text);

console.log(result.indices);    

Shim

require("regexp-match-indices").shim();

require("regexp-match-indices/shim")();

require("regexp-match-indices/auto");

 

const text = "zabbcdef";

const re = new RegExp("ab*(cd(?<Z>ef)?)");

const result = re.exec(re, text);

console.log(result.indices);    

Configuration

The polyfill can be run in two modes: "lazy" (default) or "spec-compliant". In "spec-compliant" mode, the indices property is populated and stored on the result as soon as exec() is called. This can have a significant performance penalty for existing RegExp's that do not use this feature. By default, the polyfill operates in "lazy" mode, where the indices property is defined using a getter and is only computed when first requested.

You can specify the configuration globally using the following:

require("regexp-match-indices").config.mode = "spec-compliant"; 

require("regexp-match-indices/config").mode = "spec-compliant"; 


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