regex-occurrence

Get the number of occurrences of a RegExp in a string

MIT 1 个版本
安装
npm install regex-occurrence
yarn add regex-occurrence
pnpm add regex-occurrence
bun add regex-occurrence
README

regex-occurrence Build Status

Get the number of occurrences of a RegExp in a string

Install

$ npm install --save regex-occurrence

Usage

const regexOccurrence = require('regex-occurrence');

regexOccurrence('foo bar', /F/);
//=> 0

regexOccurrence('foo bar', /Foo/i);
//=> 1

regexOccurrence('foo bar\nfoo baz', [/foo/, /baz/]);
//=> 2

regexOccurrence('foo bar\nfoo baz', [/foo/g, /baz/]);
//=> 3

API

input

Type: string

The string to search in.

Type: RegExp, RegExp[]

The regular expressions to search for.

License

MIT © Sam Verschueren

版本列表
1.0.0 2015-12-21