Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: slevithan/xregexp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.0.0
Choose a base ref
...
head repository: slevithan/xregexp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.1.0
Choose a head ref

Commits on Jul 28, 2015

  1. bower.json #63 #78

    tomascassidy committed Jul 28, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    veprbl Dmitry Kalinkin
    Copy the full SHA
    432dac8 View commit details

Commits on Sep 23, 2015

  1. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Ma27 Maximilian Bosch
    Copy the full SHA
    e6dad7e View commit details

Commits on Sep 24, 2015

  1. Minor tweaks

    slevithan committed Sep 24, 2015

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Ma27 Maximilian Bosch
    Copy the full SHA
    0ac3669 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Ma27 Maximilian Bosch
    Copy the full SHA
    098d3f3 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Ma27 Maximilian Bosch
    Copy the full SHA
    833ceb3 View commit details
  4. Update version to 3.1.0-dev

    slevithan committed Sep 24, 2015

    Verified

    This commit was signed with the committer’s verified signature. The key has expired.
    Ma27 Maximilian Bosch
    Copy the full SHA
    16535e0 View commit details
  5. Remove min directory

    slevithan committed Sep 24, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    veprbl Dmitry Kalinkin
    Copy the full SHA
    67af8c4 View commit details

Commits on Sep 25, 2015

  1. Tweak copyright headers

    slevithan committed Sep 25, 2015
    Copy the full SHA
    7563982 View commit details
  2. One more header tweak

    slevithan committed Sep 25, 2015
    Copy the full SHA
    7cac942 View commit details
  3. Readme tweaks

    slevithan committed Sep 25, 2015
    Copy the full SHA
    c8d9ac1 View commit details

Commits on Sep 26, 2015

  1. Merge pull request #91 from tomascassidy/master

    bower.json
    slevithan committed Sep 26, 2015
    Copy the full SHA
    64d3002 View commit details
  2. bower.json tweaks

    slevithan committed Sep 26, 2015
    Copy the full SHA
    d0e665d View commit details

Commits on Sep 29, 2015

  1. Minor

    slevithan committed Sep 29, 2015
    Copy the full SHA
    07b2c80 View commit details

Commits on Oct 11, 2015

  1. fix AMD detection

    The Firefox Addon SDK defines a global `define`
    function, which XRegExp's UMD stanza mistakes for
    AMD. Adding a check for `define.amd` fixes this
    and is the standard way to detect AMD:
    
    https://github.com/umdjs/umd/blob/3e14a7dfb0af2bd3a8bfe9b7b384d698e3ef75e4/amdWeb.js#L19
    chocolateboy committed Oct 11, 2015
    Copy the full SHA
    6df00ad View commit details
  2. Merge pull request #113 from chocolateboy/fix-amd

    fix AMD detection
    slevithan committed Oct 11, 2015
    Copy the full SHA
    7f68063 View commit details

Commits on Oct 12, 2015

  1. Rename self to XRegExp.

    bnjmnt4n committed Oct 12, 2015
    Copy the full SHA
    0f8e458 View commit details
  2. Merge pull request #114 from d10/master

    Rename `self` to `XRegExp`.
    slevithan committed Oct 12, 2015
    Copy the full SHA
    11362f5 View commit details

Commits on Oct 27, 2015

  1. Copy the full SHA
    8718bb9 View commit details

Commits on Oct 28, 2015

  1. Merge pull request #116 from jfahrenkrug/allow_empty_non_capt_group

    GH-112 Allow (?:)*/+/?/{1} without causing a syntax error
    slevithan committed Oct 28, 2015
    Copy the full SHA
    de83437 View commit details
  2. Build xregexp-all.js

    slevithan committed Oct 28, 2015
    Copy the full SHA
    0d9dbaa View commit details

Commits on Nov 30, 2015

  1. Code style

    slevithan committed Nov 30, 2015
    Copy the full SHA
    1ba9e1a View commit details

Commits on Dec 11, 2015

  1. Updates the package to use CommonJS and Browserify for the build

    This makes the package a proper citizen on the NPM infrastructure while maintaining `xregexp-all.js` compatibility.
    alexgorbatchev committed Dec 11, 2015
    Copy the full SHA
    a82af2c View commit details

Commits on Dec 17, 2015

  1. Copy the full SHA
    15465fd View commit details

Commits on Dec 21, 2015

  1. Merge pull request #124 from slevithan/simplify

    Simplify native flag support detection
    slevithan committed Dec 21, 2015
    Copy the full SHA
    bc41e9f View commit details
  2. Adds missing ;

    alexgorbatchev committed Dec 21, 2015
    Copy the full SHA
    6c127d3 View commit details

Commits on Dec 22, 2015

  1. Merge pull request #122 from syntaxhighlighter/master

    Updates the package to use CommonJS and Browserify for the build
    slevithan committed Dec 22, 2015
    Copy the full SHA
    300157f View commit details

Commits on Feb 15, 2016

  1. npm run build

    slevithan committed Feb 15, 2016
    Copy the full SHA
    ca3b8db View commit details
  2. Undo earlier change since Chrome supports ES6 'unicode' getter but no…

    …t flag 'u' in construction
    slevithan committed Feb 15, 2016
    Copy the full SHA
    e07f42b View commit details

Commits on Feb 21, 2016

  1. Copy the full SHA
    cc189dd View commit details
  2. Copy the full SHA
    57b3172 View commit details

Commits on Feb 22, 2016

  1. Copy the full SHA
    69e552b View commit details
  2. In XRegExp.build subpatterns, don't treat $ as trailing when followed…

    … only by escaped symbols
    slevithan committed Feb 22, 2016
    Copy the full SHA
    f546542 View commit details
  3. Copy the full SHA
    0b13ca0 View commit details

Commits on Feb 23, 2016

  1. Copy the full SHA
    d26006e View commit details
  2. Copy the full SHA
    314c78d View commit details
  3. Copy the full SHA
    bbd5b1c View commit details
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License

Copyright (c) 2007-2015 Steven Levithan <http://xregexp.com/>
Copyright (c) 2007-2016 Steven Levithan <http://xregexp.com/>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
53 changes: 21 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[XRegExp](http://xregexp.com/) 3.0.0
[XRegExp](http://xregexp.com/) 3.1.0
====================================

XRegExp provides augmented and extensible JavaScript regular expressions. You get new syntax, flags, and methods beyond what browsers support natively. XRegExp is also a regex utility belt with tools to make your client-side grepping simpler and more powerful, while freeing you from worrying about pesky cross-browser inconsistencies and things like manually manipulating `lastIndex` or slicing strings when tokenizing.
XRegExp provides augmented (and extensible) JavaScript regular expressions. You get new modern syntax and flags beyond what browsers support natively. XRegExp is also a regex utility belt with tools to make your client-side grepping and parsing easier, while freeing you from worrying about pesky aspects of JavaScript regexes like cross-browser inconsistencies and manually manipulating `lastIndex`.

XRegExp supports all native ES6 regular expression syntax. It supports Internet Explorer 5.5+, Firefox 1.5+, Chrome, Safari 3+, and Opera 11+. You can also use it with Node.js, or as a RequireJS module. The base library is about 4.25 KB, minified and gzipped.

@@ -40,15 +40,6 @@ date.test('2015-02-22'); // -> true
// The *only* caveat is that named captures must be referenced using numbered backreferences
'2015-02-22'.replace(date, '$2/$3/$1'); // -> '02/22/2015'

// If you want, you can extend native methods so you don't have to worry about this.
// Doing so also fixes numerous browser bugs in the native methods
XRegExp.install('natives');
'2015-02-22'.replace(date, '${month}/${day}/${year}'); // -> '02/22/2015'
'2015-02-22'.replace(date, function(match) {
return match.month + '/' + match.day + '/' + match.year;
}); // -> '02/22/2015'
date.exec('2015-02-22').year; // -> '2015'

// Extract every other digit from a string using XRegExp.forEach
var evens = [];
XRegExp.forEach('1a2345', /\d/, function(match, i) {
@@ -79,7 +70,7 @@ These examples should give you the flavor of what's possible, but XRegExp has mo

## Addons

You can either load addons individually, or bundle all addons together with XRegExp by loading `xregexp-all.js`. XRegExp's [npm](http://npmjs.org/) package uses `xregexp-all.js`, so addons are always available when XRegExp is installed using npm.
You can either load addons individually, or bundle all addons together with XRegExp by loading `xregexp-all.js`. XRegExp's [npm package](https://www.npmjs.com/package/xregexp) uses `xregexp-all.js`, so addons are always available when XRegExp is installed using npm.

### Unicode

@@ -106,15 +97,19 @@ XRegExp('^\\p{Hiragana}+$').test('ひらがな'); // -> true
XRegExp('^[\\p{Latin}\\p{Common}]+$').test('Über Café.'); // -> true
```

By default, `\p{…}` and `\P{…}` support the Basic Multilingual Plane (i.e. code points up to `U+FFFF`). You can opt-in to full 21-bit Unicode support (with code points up to `U+10FFFF`) on a per-regex basis by using flag `A`. In XRegExp, this is called *astral mode*. You can automatically apply astral mode for all new regexes by running `XRegExp.install('astral')`. When in astral mode, `\p{…}` and `\P{…}` always match a full code point rather than a code unit, using surrogate pairs for code points above `U+FFFF`.
By default, `\p{…}` and `\P{…}` support the Basic Multilingual Plane (i.e. code points up to `U+FFFF`). You can opt-in to full 21-bit Unicode support (with code points up to `U+10FFFF`) on a per-regex basis by using flag `A`. In XRegExp, this is called *astral mode*. You can automatically add flag `A` for all new regexes by running `XRegExp.install('astral')`. When in astral mode, `\p{…}` and `\P{…}` always match a full code point rather than a code unit, using surrogate pairs for code points above `U+FFFF`.

```js
// Using flag A. The test string uses a surrogate pair to represent U+1F4A9
XRegExp('^\\pS$', 'A').test('\uD83D\uDCA9'); // -> true
// Using flag A to match astral code points
XRegExp('^\\pS$').test('💩'); // -> false
XRegExp('^\\pS$', 'A').test('💩'); // -> true
XRegExp('(?A)^\\pS$').test('💩'); // -> true
// Using surrogate pair U+D83D U+DCA9 to represent U+1F4A9 (pile of poo)
XRegExp('(?A)^\\pS$').test('\uD83D\uDCA9'); // -> true

// Implicit flag A
XRegExp.install('astral');
XRegExp('^\\pS$').test('\uD83D\uDCA9'); // -> true
XRegExp('^\\pS$').test('💩'); // -> true
```

Opting in to astral mode disables the use of `\p{…}` and `\P{…}` within character classes. In astral mode, use e.g. `(\pL|[0-9_])+` instead of `[\pL0-9_]+`.
@@ -179,16 +174,16 @@ XRegExp.matchRecursive(str, '<div\\s*>', '</div>', 'gi', {
] */

// Omitting unneeded parts with null valueNames, and using escapeChar
str = '...{1}\\{{function(x,y){return y+x;}}';
str = '...{1}.\\{{function(x,y){return {y:x}}}';
XRegExp.matchRecursive(str, '{', '}', 'g', {
valueNames: ['literal', null, 'value', null],
escapeChar: '\\'
});
/* -> [
{name: 'literal', value: '...', start: 0, end: 3},
{name: 'value', value: '1', start: 4, end: 5},
{name: 'literal', value: '\\{', start: 6, end: 8},
{name: 'value', value: 'function(x,y){return y+x;}', start: 9, end: 35}
{name: 'literal', value: '...', start: 0, end: 3},
{name: 'value', value: '1', start: 4, end: 5},
{name: 'literal', value: '.\\{', start: 6, end: 9},
{name: 'value', value: 'function(x,y){return {y:x}}', start: 10, end: 37}
] */

// Sticky mode via flag y
@@ -213,7 +208,7 @@ Or, to bundle XRegExp with all of its addons:
<script src="xregexp-all.js"></script>
```

Using [npm](http://npmjs.org/):
Using [npm](https://www.npmjs.com/):

```bash
npm install xregexp
@@ -224,7 +219,6 @@ In [Node.js](http://nodejs.org/):
```js
var XRegExp = require('xregexp');
```
The [CommonJS](http://wiki.commonjs.org/wiki/Modules)-style `require('xregexp').XRegExp` also works.

In an AMD loader like [RequireJS](http://requirejs.org/):

@@ -234,21 +228,16 @@ require({paths: {xregexp: 'xregexp-all'}}, ['xregexp'], function(XRegExp) {
});
```

## Changelog

* Releases: [Version history](http://xregexp.com/history/).
* Upcoming: [Issue tracker](https://github.com/slevithan/xregexp/issues).

## About

XRegExp copyright 2007-2015 by [Steven Levithan](http://stevenlevithan.com/).
XRegExp copyright 2007-2016 by [Steven Levithan](http://stevenlevithan.com/).

Tools: Unicode range generators by [Mathias Bynens](http://mathiasbynens.be/), and adapted from his [unicode-data](https://github.com/mathiasbynens/unicode-data) project. Source file concatenator by [Bjarke Walling](http://twitter.com/walling).
Tools: Unicode range generators by [Mathias Bynens](http://mathiasbynens.be/), and adapted from his [unicode-data](https://github.com/mathiasbynens/unicode-data) project.

Tests: Uses [Jasmine](http://pivotal.github.com/jasmine/) for unit tests, and [Benchmark.js](http://benchmarkjs.com) for performance tests.
Tests: Uses [Jasmine](http://jasmine.github.io/) for unit tests, and [Benchmark.js](http://benchmarkjs.com) for performance tests.

Prior art: `XRegExp.build` inspired by [Lea Verou](http://lea.verou.me/)'s [RegExp.create](http://lea.verou.me/2011/03/create-complex-regexps-more-easily/). `XRegExp.union` inspired by [Ruby](http://www.ruby-lang.org/). XRegExp's syntax extensions and flags come from [Perl](http://www.perl.org/), [.NET](http://www.microsoft.com/net), etc.

All code, including addons, tools, and tests, is released under the terms of the [MIT License](http://mit-license.org/).
All code, including addons, tools, and tests, is released under the terms of the [MIT](http://mit-license.org/) license.

Fork me to show support, fix, and extend.
32 changes: 32 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "xregexp",
"version": "3.1.0",
"description": "Extended regular expressions",
"homepage": "http://xregexp.com/",
"authors": [
"Steven Levithan <steves_list@hotmail.com>"
],
"license": "MIT",
"moduleType": [
"amd",
"globals",
"node"
],
"repository": {
"type": "git",
"url": "https://github.com/slevithan/xregexp.git"
},
"keywords": [
"regex",
"regexp"
],
"main": "xregexp-all.js",
"ignore": [
"**/.*",
"package.json",
"README.md",
"src",
"tests",
"tools"
]
}
5 changes: 0 additions & 5 deletions min/xregexp-all-min.js

This file was deleted.

2 changes: 0 additions & 2 deletions min/xregexp-min.js

This file was deleted.

46 changes: 24 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
{
"name": "xregexp",
"version": "3.0.0",
"description": "Extended regular expressions",
"homepage": "http://xregexp.com/",
"author": "Steven Levithan <steves_list@hotmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/slevithan/xregexp.git"
},
"keywords": [
"regex",
"regexp"
],
"main": "xregexp-all.js",
"files": [
"LICENSE",
"xregexp-all.js"
],
"scripts": {
"build": "./tools/concatenate-source.sh"
}
"name": "xregexp",
"version": "3.1.0",
"description": "Extended regular expressions",
"homepage": "http://xregexp.com/",
"author": "Steven Levithan <steves_list@hotmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/slevithan/xregexp.git"
},
"keywords": [
"regex",
"regexp"
],
"main": "./src/index.js",
"files": [
"src"
],
"scripts": {
"build": "browserify src/index.js --standalone XRegExp > xregexp-all.js"
},
"devDependencies": {
"browserify": "^12.0.1"
}
}
43 changes: 30 additions & 13 deletions src/addons/build.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*!
* XRegExp.build 3.0.0
* <http://xregexp.com/>
* Steven Levithan (c) 2012-2015 MIT License
* Inspired by Lea Verou's RegExp.create <http://lea.verou.me/>
* XRegExp.build 3.1.0
* <xregexp.com>
* Steven Levithan (c) 2012-2016 MIT License
* Inspired by Lea Verou's RegExp.create <lea.verou.me>
*/

(function(XRegExp) {
module.exports = function(XRegExp) {
'use strict';

var REGEX_DATA = 'xregexp',
@@ -20,11 +20,17 @@
* @returns {String} Pattern with edge anchors removed.
*/
function deanchor(pattern) {
var leadingAnchor = /^\^/,
trailingAnchor = /\$$/;
// Allow any number of empty noncapturing groups before/after anchors, because regexes
// built/generated by XRegExp sometimes include them
var leadingAnchor = /^(?:\(\?:\))*\^/,
trailingAnchor = /\$(?:\(\?:\))*$/;

// Ensure that the trailing `$` isn't escaped
if (leadingAnchor.test(pattern) && trailingAnchor.test(pattern.replace(/\\[\s\S]/g, ''))) {
if (
leadingAnchor.test(pattern) &&
trailingAnchor.test(pattern) &&
// Ensure that the trailing `$` isn't escaped
trailingAnchor.test(pattern.replace(/\\[\s\S]/g, ''))
) {
return pattern.replace(leadingAnchor, '').replace(trailingAnchor, '');
}

@@ -116,7 +122,10 @@
pattern = asXRegExp(pattern);
outerCapNames = pattern[REGEX_DATA].captureNames || [];
pattern = pattern.source.replace(parts, function($0, $1, $2, $3, $4) {
var subName = $1 || $2, capName, intro;
var subName = $1 || $2,
capName,
intro,
localCapIndex;
// Named subpattern
if (subName) {
if (!data.hasOwnProperty(subName)) {
@@ -144,8 +153,12 @@
}
// Backreference
} else if (backref) {
localCapIndex = +backref - 1;
// Rewrite the backreference
return '\\' + (+backref + numPriorCaps);
return data[subName].names[localCapIndex] ?
// Need to preserve the backreference name in case using flag `n`
'\\k<' + data[subName].names[localCapIndex] + '>' :
'\\' + (+backref + numPriorCaps);
}
return match;
}) + ')';
@@ -160,13 +173,17 @@
}
// Backreference
} else if ($4) {
localCapIndex = +$4 - 1;
// Rewrite the backreference
return '\\' + outerCapsMap[+$4];
return outerCapNames[localCapIndex] ?
// Need to preserve the backreference name in case using flag `n`
'\\k<' + outerCapNames[localCapIndex] + '>' :
'\\' + outerCapsMap[+$4];
}
return $0;
});

return XRegExp(pattern, flags);
};

}(XRegExp));
};
20 changes: 10 additions & 10 deletions src/addons/matchrecursive.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*!
* XRegExp.matchRecursive 3.0.0
* <http://xregexp.com/>
* Steven Levithan (c) 2009-2015 MIT License
* XRegExp.matchRecursive 3.1.0
* <xregexp.com>
* Steven Levithan (c) 2009-2016 MIT License
*/

(function(XRegExp) {
module.exports = function(XRegExp) {
'use strict';

/**
@@ -54,16 +54,16 @@
* // ]
*
* // Omitting unneeded parts with null valueNames, and using escapeChar
* str = '...{1}\\{{function(x,y){return y+x;}}';
* str = '...{1}.\\{{function(x,y){return {y:x}}}';
* XRegExp.matchRecursive(str, '{', '}', 'g', {
* valueNames: ['literal', null, 'value', null],
* escapeChar: '\\'
* });
* // -> [
* // {name: 'literal', value: '...', start: 0, end: 3},
* // {name: 'value', value: '1', start: 4, end: 5},
* // {name: 'literal', value: '\\{', start: 6, end: 8},
* // {name: 'value', value: 'function(x,y){return y+x;}', start: 9, end: 35}
* // {name: 'literal', value: '...', start: 0, end: 3},
* // {name: 'value', value: '1', start: 4, end: 5},
* // {name: 'literal', value: '.\\{', start: 6, end: 9},
* // {name: 'value', value: 'function(x,y){return {y:x}}', start: 10, end: 37}
* // ]
*
* // Sticky mode via flag y
@@ -188,4 +188,4 @@
return output;
};

}(XRegExp));
};
12 changes: 6 additions & 6 deletions src/addons/unicode-base.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*!
* XRegExp Unicode Base 3.0.0
* <http://xregexp.com/>
* Steven Levithan (c) 2008-2015 MIT License
* XRegExp Unicode Base 3.1.0
* <xregexp.com>
* Steven Levithan (c) 2008-2016 MIT License
*/

/**
* Adds base support for Unicode matching:
* - Adds syntax `\p{..}` for matching Unicode tokens. Tokens can be inverted using `\P{..}` or
* `\p{^..}`. Token names ignore case, spaces, hyphens, and underscores. You can omit the brackets
* `\p{^..}`. Token names ignore case, spaces, hyphens, and underscores. You can omit the braces
* for token names that are a single letter (e.g. `\pL` or `PL`).
* - Adds flag A (astral), which enables 21-bit Unicode support.
* - Adds the `XRegExp.addUnicodeData` method used by other addons to provide character data.
@@ -17,7 +17,7 @@
*
* @requires XRegExp
*/
(function(XRegExp) {
module.exports = function(XRegExp) {
'use strict';

// Storage for Unicode data
@@ -233,4 +233,4 @@
XRegExp.cache.flush('patterns');
};

}(XRegExp));
};
12 changes: 6 additions & 6 deletions src/addons/unicode-blocks.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* XRegExp Unicode Blocks 3.0.0
* <http://xregexp.com/>
* Steven Levithan (c) 2010-2015 MIT License
* Unicode data provided by Mathias Bynens <http://mathiasbynens.be/>
* XRegExp Unicode Blocks 3.1.0
* <xregexp.com>
* Steven Levithan (c) 2010-2016 MIT License
* Unicode data by Mathias Bynens <mathiasbynens.be>
*/

/**
@@ -13,7 +13,7 @@
*
* @requires XRegExp, Unicode Base
*/
(function(XRegExp) {
module.exports = function(XRegExp) {
'use strict';

if (!XRegExp.addUnicodeData) {
@@ -1071,4 +1071,4 @@
}
]);

}(XRegExp));
};
12 changes: 6 additions & 6 deletions src/addons/unicode-categories.js
12 changes: 6 additions & 6 deletions src/addons/unicode-properties.js
12 changes: 6 additions & 6 deletions src/addons/unicode-scripts.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* XRegExp Unicode Scripts 3.0.0
* <http://xregexp.com/>
* Steven Levithan (c) 2010-2015 MIT License
* Unicode data provided by Mathias Bynens <http://mathiasbynens.be/>
* XRegExp Unicode Scripts 3.1.0
* <xregexp.com>
* Steven Levithan (c) 2010-2016 MIT License
* Unicode data by Mathias Bynens <mathiasbynens.be>
*/

/**
@@ -13,7 +13,7 @@
*
* @requires XRegExp, Unicode Base
*/
(function(XRegExp) {
module.exports = function(XRegExp) {
'use strict';

if (!XRegExp.addUnicodeData) {
@@ -556,4 +556,4 @@
}
]);

}(XRegExp));
};
11 changes: 11 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var XRegExp = require('./xregexp');

require('./addons/build')(XRegExp);
require('./addons/matchrecursive')(XRegExp);
require('./addons/unicode-base')(XRegExp);
require('./addons/unicode-blocks')(XRegExp);
require('./addons/unicode-categories')(XRegExp);
require('./addons/unicode-properties')(XRegExp);
require('./addons/unicode-scripts')(XRegExp);

module.exports = XRegExp;
336 changes: 165 additions & 171 deletions src/xregexp.js

Large diffs are not rendered by default.

24 changes: 2 additions & 22 deletions tests/helpers/h.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ beforeEach(function() {
XRegExp.uninstall('natives astral');
});


// Repeat a string the specified number of times
function repeat(str, num) {
return Array(num + 1).join(str);
@@ -13,31 +12,12 @@ function repeat(str, num) {
var REGEX_DATA = 'xregexp';

// Check for ES6 `u` flag support
var hasNativeU = (function() {
var isSupported = true;
try {
new RegExp('', 'u');
} catch (exception) {
isSupported = false;
}
return isSupported;
}());

var hasNativeU = XRegExp._hasNativeFlag('u');
// Check for ES6 `y` flag support
var hasNativeY = (function() {
var isSupported = true;
try {
new RegExp('', 'y');
} catch (exception) {
isSupported = false;
}
return isSupported;
}());

var hasNativeY = XRegExp._hasNativeFlag('y');
// Check for strict mode support
var hasStrictMode = (function() {'use strict'; return !this;}());


// Add the complete ES5 Array.prototype.forEach shim from <https://github.com/kriskowal/es5-shim>.
// Commented out the `if (i in self)` sparse array check because it causes this to skip keys with
// explicit undefined in IE < 9.
9 changes: 1 addition & 8 deletions tests/index.html
Original file line number Diff line number Diff line change
@@ -11,14 +11,7 @@
<script src="vendor/jasmine/boot.js"></script>

<!-- XRegExp -->
<script src="../src/xregexp.js"></script>
<script src="../src/addons/build.js"></script>
<script src="../src/addons/matchrecursive.js"></script>
<script src="../src/addons/unicode-base.js"></script>
<script src="../src/addons/unicode-blocks.js"></script>
<script src="../src/addons/unicode-categories.js"></script>
<script src="../src/addons/unicode-properties.js"></script>
<script src="../src/addons/unicode-scripts.js"></script>
<script src="../xregexp-all.js"></script>

<!-- Helpers -->
<script src="helpers/h.js"></script>
2 changes: 2 additions & 0 deletions tests/perf/index.html
Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@
var match = /[?&]version=([^&]+)/.exec(location.search);
var version = match ? match[1] : null;
var knownVersion = {
'3.1.0': true,
'3.0.0': true,
'2.0.0': true,
'1.5.1': true
};
35 changes: 22 additions & 13 deletions tests/perf/perf.js
Original file line number Diff line number Diff line change
@@ -161,11 +161,15 @@
var r = /^|(((?=x).)\2)+/;
var matches = [];
if (!r.global) {
//r = XRegExp.globalize(r);
r = new RegExp(r.source, 'g' +
(r.ignoreCase ? 'i' : '') +
(r.multiline ? 'm' : '') +
(r.sticky ? 'y' : ''));
// globalize
r = new RegExp(
r.source,
'g' +
(r.ignoreCase ? 'i' : '') +
(r.multiline ? 'm' : '') +
(r.unicode ? 'u' : '') +
(r.sticky ? 'y' : '')
);
}
str.replace(r, function(match) {
matches.push(match);
@@ -178,11 +182,15 @@
if (r.global) {
r.lastIndex = 0;
} else {
//r = XRegExp.globalize(r);
r = new RegExp(r.source, 'g' +
(r.ignoreCase ? 'i' : '') +
(r.multiline ? 'm' : '') +
(r.sticky ? 'y' : ''));
// globalize
r = new RegExp(
r.source,
'g' +
(r.ignoreCase ? 'i' : '') +
(r.multiline ? 'm' : '') +
(r.unicode ? 'u' : '') +
(r.sticky ? 'y' : '')
);
}
while (match = r.exec(str)) {
matches.push(match[0]);
@@ -203,9 +211,10 @@
})
.add('XRegExp.forEach', function() {
var r = /^|(((?=x).)\2)+/;
var matches = XRegExp.forEach(str, r, function(match) {
this.push(match[0]);
}, []);
var matches = [];
XRegExp.forEach(str, r, function(match) {
matches.push(match[0]);
});
})
);
}());
4,487 changes: 4,487 additions & 0 deletions tests/perf/versions/xregexp-all-v3.0.0.js

Large diffs are not rendered by default.

4,491 changes: 4,491 additions & 0 deletions tests/perf/versions/xregexp-all-v3.1.0.js

Large diffs are not rendered by default.

20 changes: 19 additions & 1 deletion tests/spec/s-addons-build.js
Original file line number Diff line number Diff line change
@@ -25,8 +25,15 @@ describe('XRegExp.build addon:', function() {
});

it('should strip a leading ^ and trailing unescaped $ in subpatterns, when both are present', function() {
expect(XRegExp.build('{{x}}', {x: '^123$'}).test('01234')).toBe(true);
expect(XRegExp.build('{{x}}', {x: /^123$/}).test('01234')).toBe(true);
expect(XRegExp.build('{{x}}', {x: '^123$'}).test('01234')).toBe(true);
expect(
XRegExp.build(
' (?#comment) {{sub}} ',
{sub: XRegExp(' (?#comment) ^123$ ', 'x')},
'x'
).test('01234')
).toBe(true);
});

it('should not strip a leading ^ and trailing unescaped $ in subpatterns, when both are not present', function() {
@@ -36,11 +43,22 @@ describe('XRegExp.build addon:', function() {
expect(XRegExp.build('{{x}}', {x: '123$'}).test('01234')).toBe(false);
});

it('should not strip a leading ^ and trailing unescaped $ in subpatterns, when both are present but not leading/trailing', function() {
expect(XRegExp.build('{{x}}', {x: '^1$'}).test('11')).toBe(true);
expect(XRegExp.build('{{x}}', {x: '^1$\\b'}).test('11')).toBe(false);
});

it('should not strip a trailing escaped $ in subpatterns', function() {
expect(XRegExp.build('{{x}}', {x: '^123\\$'}).test('123$')).toBe(true);
expect(XRegExp.build('{{x}}', {x: '^123\\$'}).test('0123$4')).toBe(false);
});

it('should support flag n with mixed named and unnamed groups', function() {
expect(function() {XRegExp.build('()(?<n>)\\k<n>', {}, 'n');}).not.toThrow();
expect(function() {XRegExp.build('{{a}}', {a: '()(?<n>)\\k<n>'}, 'n');}).not.toThrow();
expect(function() {XRegExp.build('()(?<x>)\\k<x>{{a}}', {a: '()(?<n>)\\k<n>'}, 'n');}).not.toThrow();
});

// TODO: Add complete specs

it('should pass the readme example', function() {
12 changes: 6 additions & 6 deletions tests/spec/s-addons-matchrecursive.js
Original file line number Diff line number Diff line change
@@ -22,18 +22,18 @@ describe('XRegExp.matchRecursive addon:', function() {
]);
});

it('should pass the readme example for omitting unneeded parts with null valueNames, and using escapeChar', function() {
var str = '...{1}\\{{function(x,y){return y+x;}}';
it('should pass the readme example for omitting unneeded parts with null valueNames and using escapeChar', function() {
var str = '...{1}.\\{{function(x,y){return {y:x}}}';
expect(
XRegExp.matchRecursive(str, '{', '}', 'g', {
valueNames: ['literal', null, 'value', null],
escapeChar: '\\'
}))
.toEqual([
{name: 'literal', value: '...', start: 0, end: 3},
{name: 'value', value: '1', start: 4, end: 5},
{name: 'literal', value: '\\{', start: 6, end: 8},
{name: 'value', value: 'function(x,y){return y+x;}', start: 9, end: 35}
{name: 'literal', value: '...', start: 0, end: 3},
{name: 'value', value: '1', start: 4, end: 5},
{name: 'literal', value: '.\\{', start: 6, end: 9},
{name: 'value', value: 'function(x,y){return {y:x}}', start: 10, end: 37}
]);
});

29 changes: 28 additions & 1 deletion tests/spec/s-xregexp.js
Original file line number Diff line number Diff line change
@@ -155,6 +155,33 @@ describe('XRegExp()', function() {
expect(function() {XRegExp('', '?');}).toThrowError(SyntaxError);
});

it('should allow (?:) followed by a quantifier as a pattern', function() {
var quantifiers = [
'?',
'??',
'*',
'*?',
'+',
'+?',
'{1}',
'{1}?',
'{1,}',
'{1,}?',
'{1,2}',
'{1,2}?'
];

for (var i = 0; i < quantifiers.length; i++) {
expect(function() {XRegExp('(?:)' + quantifiers[i]);}).not.toThrow();
}
});

it('should allow escaped \\(?:) at end of pattern', function() {
// Ensuring that any cleanup routine looking for unneeded regex parts like empty groups does
// not strip this
expect(function() {XRegExp('(\\(?:)');}).not.toThrow();
});

it('should store named capture data on regex instances', function() {
// The `captureNames` property is undocumented, so this is technically just testing
// implementation details. However, any changes to this need to be very intentional
@@ -270,7 +297,7 @@ describe('XRegExp()', function() {
it('should set properties for native flags', function() {
expect(XRegExp('(?i)').ignoreCase).toBe(true);
expect(XRegExp('(?m)').multiline).toBe(true);

var regexIM = XRegExp('(?im)');
expect(regexIM.ignoreCase).toBe(true);
expect(regexIM.multiline).toBe(true);
33 changes: 0 additions & 33 deletions tools/concatenate-source.sh

This file was deleted.

25 changes: 0 additions & 25 deletions tools/intro.js

This file was deleted.

3 changes: 0 additions & 3 deletions tools/outro.js

This file was deleted.

4,944 changes: 2,474 additions & 2,470 deletions xregexp-all.js

Large diffs are not rendered by default.