npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pcre

v0.0.6

Published

A pcre binding for node.js

Downloads

22

Readme

Description

A pcre binding for node.js with UTF8 and Unicode properties support.

Requirements

  • node.js -- v0.8.0 or newer
  • Windows, Linux, or OSX
    • BSD or OpenSolaris support is possible -- just need to generate and submit a config.h for PCRE 8.32 with these options:
./configure --enable-utf8 --enable-unicode-properties --enable-static --disable-shared --enable-jit --disable-cpp --enable-pcre8 --disable-pcre16 --disable-pcre32

Install

npm install pcre

Examples

  • Simple one-off regexp execution:
var inspect = require('util').inspect;
var PCRE = require('pcre').PCRE;

console.log(inspect(PCRE.exec("(?<nodejsrules>o)", "foo", 0), false, Infinity));

// output:
// [ 1, 2, 1, 2, named: { nodejsrules: [ 1, 2 ] } ]
  • Simple one-off regexp execution returning all matches:
var inspect = require('util').inspect;
var PCRE = require('pcre').PCRE;

console.log(inspect(PCRE.execAll("(?<nodejsrules>o)", "foo", 0), false, Infinity));

// output:
// [ [ 1, 2, 1, 2, named: { nodejsrules: [ 1, 2 ] } ],
//   [ 2, 3, 2, 3, named: { nodejsrules: [ 2, 3 ] } ] ]
  • Instantiate a regexp and test it:
var PCRE = require('pcre').PCRE;

var re = new PCRE("o");
console.log(re.test("foo", 0));
console.log(re.test("bar", 0));
console.log(re.test("node.js rules", 2));

// output:
// true
// false
// false
  • Instantiate a regexp, JIT compile it, and execute it, returning all matches:
var inspect = require('util').inspect;
var PCRE = require('pcre').PCRE;

var re = new PCRE("o");
re.study(PCRE.PCRE_STUDY_JIT_COMPILE);
console.log(inspect(re.execAll("fooooo", 0), false, Infinity));

// output:
// [ [ 1, 2 ], [ 2, 3 ], [ 3, 4 ], [ 4, 5 ], [ 5, 6 ] ]

API

PCRE static constants

All static constants for regexp flags/options and errors can be found in lib/pcre.js.

PCRE static methods

  • exec(< string >pattern, < mixed >subject, < integer >offset[, < integer >flags]) - mixed - Compiles pattern and executes it on subject starting at offset in subject. subject can be a string or Buffer. The return value is either null in case of no match, an integer error code in case of error, or an array on success containing offsets in the subject for the first match. The first two offsets reference the entirety of the matched part of the subject. Any additional offsets reference capture groups in order from left to right. Offsets for named capture groups are additionally available on the named object.

  • execAll(< string >pattern, < mixed >subject, < integer >offset[, < integer >flags]) - mixed - Same as exec() except an array of array matches is returned on success.

  • test(< string >pattern, < mixed >subject, < integer >offset[, < integer >flags]) - boolean - Similar to exec(), but used merely to test if pattern matches at least once.

  • version() - string - Returns the version and date of the PCRE library used (e.g. "8.32 2012-11-30").

PCRE methods

  • (constructor)(< string >pattern[, < integer >flags]) - Compiles pattern and returns a new PCRE instance.

  • study([< integer >flags][, < integer >jitStackStart=1, < integer >jitStackMax=32KB]) - boolean - Performs some analysis of the compiled regexp in order to optimize it. jitStackStart and jitStackMax are custom starting and maximum JIT stack sizes (in bytes) respectively for when one of the JIT flags are passed in. The return value indicates the success of the analysis.

  • set(< string >pattern[, < integer >flags]) - (void) - Compiles a new pattern and replaces the existing regexp.

  • save() - Buffer - Returns the internal state object representing the compiled regexp. Note: this does not save the result of any previous optimizations performed by study().

  • load(< Buffer >state) - (void) - Loads previously saved internal state data from save().

  • exec(< mixed >subject, < integer >offset[, < integer >flags]) - mixed - Similar to PCRE.exec().

  • execAll(< mixed >subject, < integer >offset[, < integer >flags]) - mixed - Same as exec() except an array of array matches is returned on success.

  • test(< mixed >subject, < integer >offset[, < integer >flags]) - boolean - Similar to exec(), but used merely to test if pattern matches at least once.