{"_id":"@cakoose/re2","_rev":"2-39e495701645884b5ff09614673a2b51","name":"@cakoose/re2","description":"Bindings for RE2: fast, safe alternative to backtracking regular expression engines.","dist-tags":{"latest":"1.6.0-macos-build-fix"},"versions":{"1.6.0-macos-build-fix":{"name":"@cakoose/re2","version":"1.6.0-macos-build-fix","description":"Bindings for RE2: fast, safe alternative to backtracking regular expression engines.","homepage":"http://github.com/uhop/node-re2","bugs":{"url":"http://github.com/uhop/node-re2/issues"},"main":"re2.js","directories":{"test":"tests"},"dependencies":{"nan":"^2.8.0"},"devDependencies":{"heya-unit":"^0.3.0"},"scripts":{"test":"node tests/tests.js","install":"node-gyp rebuild"},"github":"http://github.com/uhop/node-re2","repository":{"type":"git","url":"git://github.com/uhop/node-re2.git"},"keywords":["RegExp","RegEx","text processing","PCRE alternative"],"author":{"name":"Eugene Lazutkin","email":"eugene.lazutkin@gmail.com","url":"http://lazutkin.com/"},"license":"BSD-3-Clause","gypfile":true,"gitHead":"91bccfeb0e53364de2983174d95608cfb4193ff6","_id":"@cakoose/re2@1.6.0-macos-build-fix","_shasum":"575d1c36976cf94361f55673b6c4fdb5e9027a7d","_from":".","_npmVersion":"2.14.12","_nodeVersion":"4.3.1","_npmUser":{"name":"cakoose","email":"kannan@cakoose.com"},"dist":{"shasum":"575d1c36976cf94361f55673b6c4fdb5e9027a7d","tarball":"https://registry.npmjs.org/@cakoose/re2/-/re2-1.6.0-macos-build-fix.tgz","integrity":"sha512-nffyRNf5fN9m3rcQ6z8dIcHOdmAecmpbYxowFXkZsxkAsZps3nOIE0ciwCXD5tdL8Rm4fuP1gLcmSSdh95CI4A==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICKelbyKHEwE+Jb3e4BhrYSqu8q6p/25W12cYsyT2vIyAiEAwlyINwVTfvuxdYc3KFn/SpyJkvG3cPvYy8LIkDViZlE="}]},"maintainers":[{"name":"cakoose","email":"kannan@cakoose.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/re2-1.6.0-macos-build-fix.tgz_1517361684760_0.6916578724049032"}}},"readme":"# node-re2\n\n[![Build status][travis-image]][travis-url]\n[![Dependencies][deps-image]][deps-url]\n[![devDependencies][dev-deps-image]][dev-deps-url]\n[![NPM version][npm-image]][npm-url]\n\nThis project provides bindings for [RE2](https://github.com/google/re2):\nfast, safe alternative to backtracking regular expression engines written by [Russ Cox](http://swtch.com/~rsc/).\nTo learn more about RE2, start with an overview\n[Regular Expression Matching in the Wild](http://swtch.com/~rsc/regexp/regexp3.html). More resources can be found\nat his [Implementing Regular Expressions](http://swtch.com/~rsc/regexp/) page.\n\n`RE2`'s regular expression language is almost a superset of what is provided by `RegExp`\n(see [Syntax](https://github.com/google/re2/wiki/Syntax)),\nbut it lacks two features: backreferences and lookahead assertions. See below for more details.\n\n`RE2` object emulates standard `RegExp` making it a practical drop-in replacement in most cases.\n`RE2` is extended to provide `String`-based regular expression methods as well. To help converting\n`RegExp` objects to `RE2` its constructor can take `RegExp` directly honoring all properties.\n\nIt can work with [node.js buffers](http://nodejs.org/api/buffer.html) directly reducing overhead\non recoding and copying characters, and making processing/parsing long files fast.\n\n## Why use node-re2?\n\nThe built-in Node.js regular expression engine can run in exponential time with a special combination:\n - A vulnerable regular expression\n - \"Evil input\"\n\nThis can lead to what is known as a [Regular Expression Denial of Service (ReDoS)](https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS).\nTo tell if your regular expressions are vulnerable, you might try the one of these projects:\n - [rxxr2](http://www.cs.bham.ac.uk/~hxt/research/rxxr2/)\n - [safe-regex](https://github.com/substack/safe-regex)\n\nHowever, neither project is perfect.\n\nnode-re2 can protect your Node.js application from ReDoS.\nnode-re2 makes vulnerable regular expression patterns safe by evaluating them in `RE2` instead of the built-in Node.js regex engine.\n\n## Standard features\n\n`RE2` object can be created just like `RegExp`:\n\n* [`new RE2(pattern[, flags])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)\n\nSupported properties:\n\n* [`re2.lastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)\n* [`re2.global`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)\n* [`re2.ignoreCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)\n* [`re2.multiline`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)\n* [`re2.source`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)\n\nSupported methods:\n\n* [`re2.exec(str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)\n* [`re2.test(str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)\n* [`re2.toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)\n\nStarting with 1.6.0 following well-known symbol-based methods are supported (see [Symbols](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol)):\n\n* [`re2[Symbol.match](str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match)\n* [`re2[Symbol.search](str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search)\n* [`re2[Symbol.replace](str, newSubStr|function)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/replace)\n* [`re2[Symbol.split](str[, limit])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/split)\n\nIt allows to use `RE2` instances on strings directly, just like `RegExp` instances:\n\n```js\nvar re = new RE2(\"1\");\n\"213\".match(re);        // [ '1', index: 1, input: '213' ]\n\"213\".search(re);       // 1\n\"213\".replace(re, \"+\"); // 2+3\n\"213\".split(re);        // [ '2', '3' ]\n```\n\n## Extensions\n\n### Shortcut construction\n\n`RE2` object can be created from a regular expression:\n\n```js\nvar re1 = new RE2(/ab*/ig); // from a RegExp object\nvar re2 = new RE2(re1);     // from another RE2 object\n```\n\n### `String` methods\n\nStandard `String` defines four more methods that can use regular expressions. `RE2` provides them as methods\nexchanging positions of a string, and a regular expression:\n\n* `re2.match(str)`\n  * See [`str.match(regexp)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)\n* `re2.replace(str, newSubStr|function)`\n  * See [`str.replace(regexp, newSubStr|function)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)\n* `re2.search(str)`\n  * See [`str.search(regexp)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)\n* `re2.split(str[, limit])`\n  * See [`str.split(regexp[, limit])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)\n\nStarting with 1.6.0, these methods added as well-known symbol-based methods to be used transparently with ES6 string/regex machinery.\n\n### `Buffer` support\n\nIn order to support `Buffer` directly, most methods can accept buffers instead of strings. It speeds up all operations.\nFollowing signatures are supported:\n\n* `re2.exec(buf)`\n* `re2.test(buf)`\n* `re2.match(buf)`\n* `re2.search(buf)`\n* `re2.split(buf[, limit])`\n* `re2.replace(buf, replacer)`\n\nDifferences with their string-based versions:\n\n* All buffers are assumed to be encoded as [UTF-8](http://en.wikipedia.org/wiki/UTF-8)\n  (ASCII is a proper subset of UTF-8).\n* Instead of strings they return `Buffer` objects, even in composite objects. A buffer can be converted to a string with\n  [`buf.toString()`](http://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end).\n* All offsets and lengths are in bytes, rather than characters (each UTF-8 character can occupy from 1 to 4 bytes).\n  This way users can properly slice buffers without costly recalculations from characters to bytes.\n\nWhen `re2.replace()` is used with a replacer function, the replacer can return a buffer, or a string. But all arguments\n(except for an input object) will be strings, and an offset will be in characters. If you prefer to deal\nwith buffers and byte offsets in a replacer function, set a property `useBuffers` to `true` on the function:\n\n```js\nfunction strReplacer(match, offset, input) {\n\t// typeof match == \"string\"\n\treturn \"<= \" + offset + \" characters|\";\n}\n\nRE2(\"б\").replace(\"абв\", strReplacer);\n// \"а<= 1 characters|в\"\n\nfunction bufReplacer(match, offset, input) {\n\t// typeof match == \"string\"\n\treturn \"<= \" + offset + \" bytes|\";\n}\nbufReplacer.useBuffers = true;\n\nRE2(\"б\").replace(\"абв\", bufReplacer);\n// \"а<= 2 bytes|в\"\n```\n\nThis feature works for string and buffer inputs. If a buffer was used as an input, its output will be returned as\na buffer too, otherwise a string will be returned.\n\n### Calculate length\n\nTwo functions to calculate string sizes between\n[UTF-8](http://en.wikipedia.org/wiki/UTF-8) and\n[UTF-16](http://en.wikipedia.org/wiki/UTF-16) are exposed on `RE2`:\n\n* `RE2.getUtf8Length(str)` &mdash; calculates a buffer size in bytes to encode a UTF-16 string as\n  a UTF-8 buffer.\n* `RE2.getUtf16Length(buf)` &mdash; calculates a string size in characters to encode a UTF-8 buffer as\n  a UTF-16 string.\n\nJavaScript supports UCS-2 strings with 16-bit characters, while node.js 0.11 supports full UTF-16 as\na default string.\n\n## How to install\n\nInstallation:\n\n```\nnpm install re2\n```\n\n## How to use\n\nIt is used just like a `RegExp` object.\n\n```js\nvar RE2 = require(\"re2\");\n\n// with default flags\nvar re = new RE2(\"a(b*)\");\nvar result = re.exec(\"abbc\");\nconsole.log(result[0]); // \"abb\"\nconsole.log(result[1]); // \"bb\"\n\nresult = re.exec(\"aBbC\");\nconsole.log(result[0]); // \"a\"\nconsole.log(result[1]); // \"\"\n\n// with explicit flags\nre = new RE2(\"a(b*)\", \"i\");\nresult = re.exec(\"aBbC\");\nconsole.log(result[0]); // \"aBb\"\nconsole.log(result[1]); // \"Bb\"\n\n// from regular expression object\nvar regexp = new RegExp(\"a(b*)\", \"i\");\nre = new RE2(regexp);\nresult = re.exec(\"aBbC\");\nconsole.log(result[0]); // \"aBb\"\nconsole.log(result[1]); // \"Bb\"\n\n// from regular expression literal\nre = new RE2(/a(b*)/i);\nresult = re.exec(\"aBbC\");\nconsole.log(result[0]); // \"aBb\"\nconsole.log(result[1]); // \"Bb\"\n\n// from another RE2 object\nvar rex = new RE2(re);\nresult = rex.exec(\"aBbC\");\nconsole.log(result[0]); // \"aBb\"\nconsole.log(result[1]); // \"Bb\"\n\n// shortcut\nresult = new RE2(\"ab*\").exec(\"abba\");\n\n// factory\nresult = RE2(\"ab*\").exec(\"abba\");\n```\n\n## Limitations (Things RE2 does not support)\n\n`RE2` consciously avoids any regular expression features that require worst-case exponential time to evaluate.\nThese features are essentially those that describe a Context-Free Language (CFL) rather than a Regular Expression,\nand are extensions to the traditional regular expression language because some people don't know when enough is enough.\n\nThe most noteworthy missing features are backreferences and lookahead assertions.\nIf your application uses these features, you should continue to use `RegExp`.\nBut since these features are fundamentally vulnerable to\n[ReDoS](https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS),\nyou should strongly consider replacing them.\n\n`RE2` will throw a `SyntaxError` if you try to declare a regular expression using these features.\nIf you are evaluating an externally-provided regular expression, wrap your `RE2` declarations in a try-catch block. It allows to use `RegExp`, when `RE2` misses a feature:\n\n```js\nvar re = /(a)+(b)*/;\ntry {\n  re = new RE2(re);\n  // use RE2 as a drop-in replacement\n} catch (e) {\n  // suppress an error, and use\n  // the original RegExp\n}\nvar result = re.exec(sample);\n```\n\nIn addition to these missing features, `RE2` also behaves somewhat differently from the built-in regular expression engine in corner cases.\n\n### Backreferences\n\n`RE2` doesn't support backreferences, which are numbered references to previously\nmatched groups, like so: `\\1`, `\\2`, and so on. Example of backrefrences:\n\n```js\n/(cat|dog)\\1/.test(\"catcat\"); // true\n/(cat|dog)\\1/.test(\"dogdog\"); // true\n/(cat|dog)\\1/.test(\"catdog\"); // false\n/(cat|dog)\\1/.test(\"dogcat\"); // false\n```\n\n### Lookahead assertions\n\n`RE2` doesn't support lookahead assertions, which are ways to allow a matching dependent on subsequent contents.\n\n```js\n/abc(?=def)/; // match abc only if it is followed by def\n/abc(?!def)/; // match abc only if it is not followed by def\n```\n\n### Mismatched behavior\n\n`RE2` and the built-in regex engines disagree a bit.\nBefore you switch to `RE2`, verify that your regular expressions continue to work as expected.\nThey should do so in the vast majority of cases.\n\nHere is an example of a case where they may not:\n\n```js\nvar RE2  = require(\"../re2\");\n\nvar pattern = '(?:(a)|(b)|(c))+';\n\nvar built_in = new RegExp(pattern);\nvar re2 = new RE2(pattern);\n\nvar input = 'abc';\n\nvar bi_res = built_in.exec(input);\nvar re2_res = re2.exec(input);\n\nconsole.log('bi_res: ' + bi_res);    // prints: bi_res: abc,,,c\nconsole.log('re2_res : ' + re2_res); // prints: re2_res : abc,a,b,c\n```\n\n## Working on this project\n\nThis project uses git submodules, so the correct way to get it is:\n\n    git clone git@github.com:uhop/node-re2.git\n    cd node-re2\n    git submodule update --init --recursive\n\nIn order to build it, make sure that you have all necessary `gyp` dependencies\nfor your platform, then run:\n\n    npm install\n\nOr:\n\n    yarn\n\n## Release history\n\n- 1.6.0 *Added well-known symbol-based methods of ES6. Refreshed NAN.*\n- 1.5.0 *Bug fixes, error checks, better docs. Thx [Jamie Davis](https://github.com/davisjam), and [omg](https://github.com/omg)!*\n- 1.4.1 *Minor corrections in README.*\n- 1.4.0 *Use re2 as a git submodule. Thx [Ben James](https://github.com/benhjames)!*\n- 1.3.3 *Refreshed dependencies.*\n- 1.3.2 *Updated references in README (re2 was moved to github).*\n- 1.3.1 *Refreshed dependencies, new Travis-CI config.*\n- 1.3.0 *Upgraded NAN to 1.6.3, now we support node.js 0.10.36, 0.12.0, and io.js 1.3.0. Thx @reid!*\n- 1.2.0 *Documented getUtfXLength() functions. Added support for `\\c` and `\\u` commands.*\n- 1.1.1 *Minor corrections in README.*\n- 1.1.0 *Buffer-based API is public. Unicode is fully supported.*\n- 1.0.0 *Implemented all `RegExp` methods, and all relevant `String` methods.*\n- 0.9.0 *The initial public release.*\n\n## License\n\nBSD\n\n[npm-image]:      https://img.shields.io/npm/v/re2.svg\n[npm-url]:        https://npmjs.org/package/re2\n[deps-image]:     https://img.shields.io/david/uhop/node-re2.svg\n[deps-url]:       https://david-dm.org/uhop/node-re2\n[dev-deps-image]: https://img.shields.io/david/dev/uhop/node-re2.svg\n[dev-deps-url]:   https://david-dm.org/uhop/node-re2?type=dev\n[travis-image]:   https://img.shields.io/travis/uhop/node-re2.svg\n[travis-url]:     https://travis-ci.org/uhop/node-re2\n","maintainers":[{"name":"cakoose","email":"kannan@cakoose.com"}],"time":{"modified":"2022-06-12T15:37:14.780Z","created":"2018-01-31T01:21:24.895Z","1.6.0-macos-build-fix":"2018-01-31T01:21:24.895Z"},"homepage":"http://github.com/uhop/node-re2","keywords":["RegExp","RegEx","text processing","PCRE alternative"],"repository":{"type":"git","url":"git://github.com/uhop/node-re2.git"},"author":{"name":"Eugene Lazutkin","email":"eugene.lazutkin@gmail.com","url":"http://lazutkin.com/"},"bugs":{"url":"http://github.com/uhop/node-re2/issues"},"license":"BSD-3-Clause","readmeFilename":"README.md"}