Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

re2

Package Overview
Dependencies
Maintainers
1
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

re2 - npm Package Compare versions

Comparing version 0.9.0 to 1.0.0

lib/toString.cc

2

package.json
{
"name": "re2",
"version": "0.9.0",
"version": "1.0.0",
"description": "node.js bindings for RE2: fast, safe alternative to backtracking regular expression engines.",

@@ -5,0 +5,0 @@ "homepage": "http://github.com/uhop/node-re2",

@@ -8,25 +8,37 @@ # node-re2

node.js bindings for [RE2](https://code.google.com/p/re2/):
fast, safe alternative to backtracking regular expression engines. The trade-offs for speed: lack of backreferences
and zero-width assertions. See below for more details.
This project is node.js bindings for [RE2](https://code.google.com/p/re2/):
fast, safe alternative to backtracking regular expression engines.
Its regular expression language is almost a superset of what is provided by `RegExp`,
but it lacks one feature: backreferences. See below for more details.
`RE2` object emulates standard `RegExp`, and supports folowing properties:
`RE2` object emulates standard `RegExp` making it a practical drop-in replacement in most cases.
`RE2` is extended to provide `String`-based regular expression methods as well. To help converting
`RegExp` objects to `RE2` its constructor can take `RegExp` directly honoring all properties.
* [`lastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
* [`global`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
* [`ignoreCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
* [`multiline`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
* [`source`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
## Standard features
And following methods:
It can be created just like `RegExp`:
* [`exec(str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
* [`test(str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
* [`new RE2(pattern[, flags])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
It can be created like `RegExp`:
Supported properties:
* [`new RE2(pattern[, flags])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp)
* [`re2.lastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex)
* [`re2.global`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global)
* [`re2.ignoreCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase)
* [`re2.multiline`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline)
* [`re2.source`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source)
Additionally it can be created from a regular expression `new RE2(regexp)`:
Supported methods:
* [`re2.exec(str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec)
* [`re2.test(str)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/test)
* [`re2.toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/toString)
## Extensions
The following is the list of extensions.
`RE2` object can be created from a regular expression:
```js

@@ -37,2 +49,14 @@ var re1 = new RE2(/ab*/ig); // from RegExp object

Standard `String` defines four more methods that can use regular expressions. `RE2` provides as methods
exchanging positions of a string, and a regular expression:
* `re2.match(str)` vs.
[`str.match(regexp)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/match)
* `re2.replace(str, newSubStr|function)` vs.
[`str.replace(regexp, newSubStr|function)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)
* `re2.search(str)` vs.
[`str.search(regexp)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search)
* `re2.split(str[, limit])` vs.
[`str.split(regexp[, limit]])`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
## How to install

@@ -46,5 +70,52 @@

## How to use
```js
var RE2 = require("re2");
// with default flags
var re = new RE2("a(b*)");
var result = re.exec("abbc");
console.log(result[0]); // "abb"
console.log(result[1]); // "bb"
result = re.exec("aBbC");
console.log(result[0]); // "a"
console.log(result[1]); // ""
// with explicit flags
re = new RE2("a(b*)", "i");
result = re.exec("aBbC");
console.log(result[0]); // "aBb"
console.log(result[1]); // "Bb"
// from regular expression object
var regexp = new RegExp("a(b*)", "i");
re = new RE2(regexp);
result = re.exec("aBbC");
console.log(result[0]); // "aBb"
console.log(result[1]); // "Bb"
// from regular expression literal
re = new RE2(/a(b*)/i);
result = re.exec("aBbC");
console.log(result[0]); // "aBb"
console.log(result[1]); // "Bb"
// from another RE2 object
var rex = new RE2(re);
result = rex.exec("aBbC");
console.log(result[0]); // "aBb"
console.log(result[1]); // "Bb"
// shortcut
result = new RE2("ab*").exec("abba");
// factory
result = RE2("ab*").exec("abba");
```
## Backreferences
Unlike the standard `RegExp`, `RE2` doesn't support backreferences, which are numbered references to previously
Unlike `RegExp`, `RE2` doesn't support backreferences, which are numbered references to previously
matched groups, like so: `\1`, `\2`, and so on. Example of backrefrences:

@@ -59,6 +130,7 @@

If this kind of matching is essential for your application, you should use `RegExp`.
If your application uses this kind of matching, you should use `RegExp`.
## Release history
- 1.0.0 *implemeted all `RegExp` methods, and all relevant `String` methods*
- 0.9.0 *the initial public release*

@@ -65,0 +137,0 @@

@@ -16,3 +16,5 @@ "use strict";

"use strict";
var re = new RE2("quick\\s(brown).+?(jumps)", "ig");
eval(t.TEST("re.source === 'quick\\\\s(brown).+?(jumps)'"));

@@ -22,3 +24,5 @@ eval(t.TEST("re.ignoreCase"));

eval(t.TEST("!re.multiline"));
var result = re.exec("The Quick Brown Fox Jumps Over The Lazy Dog");
eval(t.TEST("t.unify(result, ['Quick Brown Fox Jumps', 'Brown', 'Jumps'])"));

@@ -31,13 +35,20 @@ eval(t.TEST("result.index === 4"));

"use strict";
var str = "abbcdefabh";
var re = new RE2("ab*", "g");
var str = "abbcdefabh";
var result = re.exec(str);
eval(t.TEST("!!result"));
eval(t.TEST("result[0] === 'abb'"));
eval(t.TEST("re.lastIndex === 3"));
result = re.exec(str);
eval(t.TEST("!!result"));
eval(t.TEST("result[0] === 'ab'"));
eval(t.TEST("re.lastIndex === 9"));
result = re.exec(str);
eval(t.TEST("!result"));

@@ -47,6 +58,8 @@ },

"use strict";
var re = new RE2("(hello \\S+)");
var result = re.exec("This is a hello world!");
eval(t.TEST("result[1] === 'hello world!'"));
}
]);

@@ -13,2 +13,3 @@ "use strict";

"use strict";
eval(t.TEST("!!RE2"));

@@ -20,9 +21,30 @@ eval(t.TEST("RE2.toString() === 'function RE2() { [native code] }'"));

"use strict";
var re = new RE2("\\d+");
eval(t.TEST("!!re"));
eval(t.TEST("re instanceof RE2"));
var re1 = new RE2("\\d+");
eval(t.TEST("!!re1"));
eval(t.TEST("re1 instanceof RE2"));
var re2 = RE2("\\d+");
eval(t.TEST("!!re2"));
eval(t.TEST("re2 instanceof RE2"));
compare(re1, re2, t);
re1 = new RE2("\\d+", "m");
eval(t.TEST("!!re1"));
eval(t.TEST("re1 instanceof RE2"));
re2 = RE2("\\d+", "m");
eval(t.TEST("!!re2"));
eval(t.TEST("re2 instanceof RE2"));
compare(re1, re2, t);
},
function test_generalIn(t) {
"use strict";
var re = new RE2("\\d+");
eval(t.TEST("'exec' in re"));

@@ -42,3 +64,5 @@ eval(t.TEST("'test' in re"));

"use strict";
var re = new RE2("\\d+");
eval(t.TEST("typeof re.exec == 'function'"));

@@ -58,7 +82,13 @@ eval(t.TEST("typeof re.test == 'function'"));

"use strict";
var re = new RE2("\\d+");
eval(t.TEST("re.lastIndex === 0"));
re.lastIndex = 5;
eval(t.TEST("re.lastIndex === 5"));
re.lastIndex = 0;
eval(t.TEST("re.lastIndex === 0"));

@@ -68,21 +98,37 @@ },

"use strict";
var re1 = new RegExp("\\d+");
var re2 = new RE2("\\d+");
compare(re1, re2, t);
re2 = new RE2(re1);
compare(re1, re2, t);
re1 = new RegExp("a", "ig");
re2 = new RE2("a", "ig");
compare(re1, re2, t);
re2 = new RE2(re1);
compare(re1, re2, t);
re1 = /\s/gm;
re2 = new RE2("\\s", "mg");
compare(re1, re2, t);
re2 = new RE2(re1);
compare(re1, re2, t);
re2 = new RE2(/\s/gm);
compare(/\s/gm, re2, t);
re1 = new RE2("b", "gm");
re2 = new RE2(re1);
compare(re1, re2, t);

@@ -89,0 +135,0 @@ }

@@ -14,5 +14,7 @@ "use strict";

unit.add(module, [
function test_fromExec(t) {
function test_testFromExec(t) {
"use strict";
var re = new RE2("quick\\s(brown).+?(jumps)", "ig");
eval(t.TEST("re.test('The Quick Brown Fox Jumps Over The Lazy Dog')"));

@@ -23,19 +25,30 @@ eval(t.TEST("re.test('tHE qUICK bROWN fOX jUMPS oVER tHE lAZY dOG')"));

eval(t.TEST("!re.test('THE KWIK BROWN FOX JUMPS OVER THE LAZY DOG')"));
re = new RE2("ab*", "g");
eval(t.TEST("re.test('abbcdefabh')"));
eval(t.TEST("!re.test('qwerty')"));
re = new RE2("(hello \\S+)");
eval(t.TEST("re.test('This is a hello world!')"));
eval(t.TEST("!re.test('This is a Hello world!')"));
},
function test_execSucc(t) {
function test_testSimple(t) {
"use strict";
var str = "abbcdefabh";
var re1 = new RE2("ab*", "g");
eval(t.TEST("re1.test(str)"));
var re2 = new RE2("ab*");
eval(t.TEST("re2.test(str)"));
var re3 = new RE2("abc");
eval(t.TEST("!re3.test(str)"));
}
]);

@@ -6,7 +6,12 @@ "use strict";

var testGeneral = require("./test_general");
var testExec = require("./test_exec");
var testTest = require("./test_test");
var testGeneral = require("./test_general");
var testExec = require("./test_exec");
var testTest = require("./test_test");
var testToString = require("./test_toString");
var testMatch = require("./test_match");
var testReplace = require("./test_replace");
var testSearch = require("./test_search");
var testSplit = require("./test_split");
unit.run();

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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