Socket
Socket
Sign inDemoInstall

match-point

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

match-point

Find all pattern matches and return the specified submatch for each


Version published
Weekly downloads
6
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

Find all pattern matches and return the specified submatch for each

Synposis

function(string, regex, captureGroup)

Usage

var match = require('match-point');
var string = 'Alice A. Adams, MD, Bob B. Baker, BA, Dr. Charlie C. Chase, PhD';
match(string, / ([A-Z])\. /); // ['A', 'B', 'C']
match(string, / ([A-Z])\. \w+, (MD|MS|PhD)/); // ['MD', 'PhD']
match(string, / ([A-Z])\. \w+, (MD|MS|PhD)/, 1); // ['A', 'C']

Description

Find all pattern matches in string matching regex and return in an array.

For each element:

  • When there are no capture groups in the regex, the entire pattern match is returned.
  • When there are capture groups in the regex:
    • When captureGroup is undefined, the last submatch is returned.
    • When captureGroup is defined, it indicates which submatch to return (0 being the entire match, etc., per String.prototype.match results).

Caveats

Don't use global flag in your regex. It's unnecessary and suppresses submatches of capture groups.

FAQs

Package last updated on 25 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc