{"id":16834698,"url":"https://github.com/mscdex/node-pcre","last_synced_at":"2025-03-22T04:30:46.863Z","repository":{"id":6572355,"uuid":"7814337","full_name":"mscdex/node-pcre","owner":"mscdex","description":"A pcre binding for node.js","archived":false,"fork":false,"pushed_at":"2014-08-15T13:47:36.000Z","size":1180,"stargazers_count":39,"open_issues_count":8,"forks_count":9,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-01T12:51:47.555Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mscdex.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-25T05:37:52.000Z","updated_at":"2023-08-01T23:05:34.000Z","dependencies_parsed_at":"2022-09-26T17:01:05.132Z","dependency_job_id":null,"html_url":"https://github.com/mscdex/node-pcre","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fnode-pcre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fnode-pcre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fnode-pcre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mscdex%2Fnode-pcre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mscdex","download_url":"https://codeload.github.com/mscdex/node-pcre/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244181419,"owners_count":20411603,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-13T12:07:26.488Z","updated_at":"2025-03-22T04:30:45.999Z","avatar_url":"https://github.com/mscdex.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"Description\n===========\n\nA pcre binding for [node.js](http://nodejs.org/) with UTF8 and Unicode properties support.\n\n\nRequirements\n============\n\n* [node.js](http://nodejs.org/) -- v0.8.0 or newer\n* Windows, Linux, or OSX\n  * BSD or OpenSolaris support is possible -- just need to generate and submit a config.h for [PCRE 8.32](ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz) with these options:\n```\n./configure --enable-utf8 --enable-unicode-properties --enable-static --disable-shared --enable-jit --disable-cpp --enable-pcre8 --disable-pcre16 --disable-pcre32\n```\n\n\nInstall\n=======\n\n    npm install pcre\n\n\nExamples\n========\n\n* Simple one-off regexp execution:\n\n```javascript\nvar inspect = require('util').inspect;\nvar PCRE = require('pcre').PCRE;\n\nconsole.log(inspect(PCRE.exec(\"(?\u003cnodejsrules\u003eo)\", \"foo\", 0), false, Infinity));\n\n// output:\n// [ 1, 2, 1, 2, named: { nodejsrules: [ 1, 2 ] } ]\n```\n\n* Simple one-off regexp execution returning all matches:\n\n```javascript\nvar inspect = require('util').inspect;\nvar PCRE = require('pcre').PCRE;\n\nconsole.log(inspect(PCRE.execAll(\"(?\u003cnodejsrules\u003eo)\", \"foo\", 0), false, Infinity));\n\n// output:\n// [ [ 1, 2, 1, 2, named: { nodejsrules: [ 1, 2 ] } ],\n//   [ 2, 3, 2, 3, named: { nodejsrules: [ 2, 3 ] } ] ]\n```\n\n* Instantiate a regexp and test it:\n\n```javascript\nvar PCRE = require('pcre').PCRE;\n\nvar re = new PCRE(\"o\");\nconsole.log(re.test(\"foo\", 0));\nconsole.log(re.test(\"bar\", 0));\nconsole.log(re.test(\"node.js rules\", 2));\n\n// output:\n// true\n// false\n// false\n```\n\n* Instantiate a regexp, JIT compile it, and execute it, returning all matches:\n\n```javascript\nvar inspect = require('util').inspect;\nvar PCRE = require('pcre').PCRE;\n\nvar re = new PCRE(\"o\");\nre.study(PCRE.PCRE_STUDY_JIT_COMPILE);\nconsole.log(inspect(re.execAll(\"fooooo\", 0), false, Infinity));\n\n// output:\n// [ [ 1, 2 ], [ 2, 3 ], [ 3, 4 ], [ 4, 5 ], [ 5, 6 ] ]\n```\n\n\nAPI\n===\n\nPCRE static constants\n---------------------\n\nAll static constants for regexp flags/options and errors can be found in `lib/pcre.js`.\n\n\nPCRE static methods\n-------------------\n\n* **exec**(\u003c _string_ \u003epattern, \u003c _mixed_ \u003esubject, \u003c _integer_ \u003eoffset[, \u003c _integer_ \u003eflags]) - _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.\n\n* **execAll**(\u003c _string_ \u003epattern, \u003c _mixed_ \u003esubject, \u003c _integer_ \u003eoffset[, \u003c _integer_ \u003eflags]) - _mixed_ - Same as exec() except an _array_ of _array_ matches is returned on success.\n\n* **test**(\u003c _string_ \u003epattern, \u003c _mixed_ \u003esubject, \u003c _integer_ \u003eoffset[, \u003c _integer_ \u003eflags]) - _boolean_ - Similar to exec(), but used merely to test if `pattern` matches at least once.\n\n* **version**() - _string_ - Returns the version and date of the PCRE library used (e.g. \"8.32 2012-11-30\").\n\n\nPCRE methods\n------------\n\n* **(constructor)**(\u003c _string_ \u003epattern[, \u003c _integer_ \u003eflags]) - Compiles `pattern` and returns a new PCRE instance.\n\n* **study**([\u003c _integer_ \u003eflags][, \u003c _integer_ \u003ejitStackStart=1, \u003c _integer_ \u003ejitStackMax=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.\n\n* **set**(\u003c _string_ \u003epattern[, \u003c _integer_ \u003eflags]) - _(void)_ - Compiles a new `pattern` and replaces the existing regexp.\n\n* **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().\n\n* **load**(\u003c _Buffer_ \u003estate) - _(void)_ - Loads previously saved internal state data from save().\n\n* **exec**(\u003c _mixed_ \u003esubject, \u003c _integer_ \u003eoffset[, \u003c _integer_ \u003eflags]) - _mixed_ - Similar to PCRE.exec().\n\n* **execAll**(\u003c _mixed_ \u003esubject, \u003c _integer_ \u003eoffset[, \u003c _integer_ \u003eflags]) - _mixed_ - Same as exec() except an _array_ of _array_ matches is returned on success.\n\n* **test**(\u003c _mixed_ \u003esubject, \u003c _integer_ \u003eoffset[, \u003c _integer_ \u003eflags]) - _boolean_ - Similar to exec(), but used merely to test if `pattern` matches at least once.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fnode-pcre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmscdex%2Fnode-pcre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmscdex%2Fnode-pcre/lists"}