Permalink
Browse files

Minor.

  • Loading branch information...
1 parent 7ab3698 commit bf9045a3a54116a97a7564b4fb13a267edf3028f @slevithan committed Oct 16, 2012
Showing with 20 additions and 17 deletions.
  1. +12 −11 README.md
  2. +3 −2 src/xregexp.js
  3. +1 −1 tools/intro.js
  4. +4 −3 xregexp-all.js
View
@@ -9,7 +9,7 @@ See [what's new in version 3.0.0-pre](https://github.com/slevithan/xregexp/wiki/
## Performance
-XRegExp regexes compile to native `RegExp` objects, and therefore perform just as fast as native regular expressions. There is a small extra cost when compiling a pattern for the first time.
+XRegExp regexes compile to native `RegExp` objects, and therefore perform just as fast as native regular expressions. There is a tiny extra cost when compiling a pattern for the first time.
## Usage examples
@@ -71,8 +71,8 @@ XRegExp.matchChain(html, [
]); // -> ['xregexp.com', 'www.google.com']
// Merge strings and regexes into a single pattern, safely rewriting backreferences
-XRegExp.union(['a+b*c', /(dogs)\1/, /(cats)\1/], 'i');
-// -> /a\+b\*c|(dogs)\1|(cats)\2/i
+XRegExp.union(['a+b*c', /(dog)\1/, /(cat)\1/], 'i');
+// -> /a\+b\*c|(dog)\1|(cat)\2/i
```
These examples should give you the flavor of what's possible, but XRegExp has more syntax, flags, methods, options, and browser fixes that aren't shown here. You can even augment XRegExp's regular expression syntax with addons (see below) or write your own. See [xregexp.com](http://xregexp.com/) for more details.
@@ -106,7 +106,7 @@ 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 implicitly 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 implicitly 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`.
```js
// Using flag A. The test string uses a surrogate pair to represent U+1F4A9
@@ -117,9 +117,9 @@ XRegExp.install('astral');
XRegExp('^\\pS$').test('\uD83D\uDCA9'); // -> true
```
-Opting in to astral mode disables the use of `\p{…}` and `\P{…}` within character classes. In astral mode, use e.g. `(?:\pL|\pM|[0-9_])+` instead of `[\pL\pM0-9_]+`.
+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_]+`.
-XRegExp uses Unicode 6.2.0. Support for astral code points is new in XRegExp 3.0.0.
+XRegExp uses Unicode 6.2.0.
### XRegExp.build
@@ -145,7 +145,7 @@ time.test('10:59'); // -> true
XRegExp.exec('10:59', time).minutes; // -> '59'
```
-Named subpatterns can be provided as strings or regex objects. A leading `^` and trailing unescaped `$` are stripped from subpatterns if both are present, which allows embedding independently-useful anchored patterns. `{{…}}` tokens can be quantified as a single unit. Backreferences in the outer pattern and provided subpatterns are automatically renumbered to work correctly within the larger combined pattern. The syntax `({{name}})` works as shorthand for named capture via `(?<name>{{name}})`. Named subpatterns cannot be embedded within character classes.
+Named subpatterns can be provided as strings or regex objects. A leading `^` and trailing unescaped `$` are stripped from subpatterns if both are present, which allows embedding independently-useful anchored patterns. `{{…}}` tokens can be quantified as a single unit. Any backreferences in the outer pattern or provided subpatterns are automatically renumbered to work correctly within the larger combined pattern. The syntax `({{name}})` works as shorthand for named capture via `(?<name>{{name}})`. Named subpatterns cannot be embedded within character classes.
See also: *[Creating Grammatical Regexes Using XRegExp.build](http://blog.stevenlevithan.com/archives/grammatical-patterns-xregexp-build)*.
@@ -197,7 +197,7 @@ XRegExp.matchRecursive(str, '<', '>', 'gy');
// -> ['1', '<<2>>', '3']
```
-`XRegExp.matchRecursive` throws an error if it sees an unbalanced delimiter in the target string.
+`XRegExp.matchRecursive` throws an error if it scans past an unbalanced delimiter in the target string.
## Installation and usage
@@ -222,8 +222,9 @@ npm install xregexp
In [Node.js](http://nodejs.org/):
```js
-var XRegExp = require('xregexp').XRegExp;
+var XRegExp = require('xregexp'); // Requires XRegExp 3.0
```
+The [CommonJS](http://wiki.commonjs.org/wiki/Modules)-style `require('xregexp').XRegExp` also works, and is the only method supported by XRegExp 2.0.
In an AMD loader like [RequireJS](http://requirejs.org/):
@@ -240,14 +241,14 @@ require({paths: {xregexp: 'build/xregexp-all-min'}}, ['xregexp'], function(XRegE
## About
-XRegExp and addons copyright 2007-2012 by [Steven Levithan](http://stevenlevithan.com/).
+XRegExp copyright 2007-present 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).
Tests: Uses [Jasmine](http://pivotal.github.com/jasmine/) 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, are 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 License](http://mit-license.org/).
Fork me to show support, fix, and extend.
View
@@ -1148,8 +1148,9 @@ var XRegExp = (function(undefined) {
/**
* Returns an XRegExp object that is the union of the given patterns. Patterns can be provided as
* regex objects or strings. Metacharacters are escaped in patterns provided as strings.
- * Backreferences in provided regex objects are automatically renumbered to work correctly. Native
- * flags used by provided regexes are ignored in favor of the `flags` argument.
+ * Backreferences in provided regex objects are automatically renumbered to work correctly within
+ * the larger combined pattern. Native flags used by provided regexes are ignored in favor of the
+ * `flags` argument.
* @memberOf XRegExp
* @param {Array} patterns Regexes and strings to combine.
* @param {String} [flags] Any combination of XRegExp flags.
View
@@ -1,5 +1,5 @@
/*!
- * XRegExp All 3.0.0-pre
+ * XRegExp-All 3.0.0-pre
* <http://xregexp.com/>
* Steven Levithan © 2012 MIT License
*/
View
@@ -1,5 +1,5 @@
/*!
- * XRegExp All 3.0.0-pre
+ * XRegExp-All 3.0.0-pre
* <http://xregexp.com/>
* Steven Levithan © 2012 MIT License
*/
@@ -1175,8 +1175,9 @@ var XRegExp = (function(undefined) {
/**
* Returns an XRegExp object that is the union of the given patterns. Patterns can be provided as
* regex objects or strings. Metacharacters are escaped in patterns provided as strings.
- * Backreferences in provided regex objects are automatically renumbered to work correctly. Native
- * flags used by provided regexes are ignored in favor of the `flags` argument.
+ * Backreferences in provided regex objects are automatically renumbered to work correctly within
+ * the larger combined pattern. Native flags used by provided regexes are ignored in favor of the
+ * `flags` argument.
* @memberOf XRegExp
* @param {Array} patterns Regexes and strings to combine.
* @param {String} [flags] Any combination of XRegExp flags.

0 comments on commit bf9045a

Please sign in to comment.