Skip to content

Commit fc69aaf

Browse files
committed
readme: add notes about using xregexp with npm
1 parent f990e41 commit fc69aaf

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

README.md

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
XRegExp provides augmented, extensible, cross-browser JavaScript regular expressions. You get new syntax and flags beyond what browsers support natively, along with a collection of utils to make your client-side grepping and parsing easier. XRegExp also frees you from worrying about pesky inconsistencies in cross-browser regex handling and the dubious `lastIndex` property.
55

6-
XRegExp supports all native ES5 regular expression syntax. It clocks in at ~3.5 KB when minified and gzipped, and it works with Internet Explorer 5.5+, Firefox 1.5+, Chrome, Safari 3+, and Opera 9.5+.
6+
XRegExp supports all native ES5 regular expression syntax. It's about 3.5 KB when minified and gzipped. It works with Internet Explorer 5.5+, Firefox 1.5+, Chrome, Safari 3+, and Opera 9.5+.
77

88

99
## Performance
@@ -75,12 +75,17 @@ XRegExp.union(['a+b*c', /(dogs)\1/, /(cats)\1/], 'i');
7575
// -> /a\+b\*c|(dogs)\1|(cats)\2/i
7676
~~~
7777

78-
These examples should give you the flavor of what's possible, but XRegExp has plenty more syntax, flags, utils, 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.
78+
These examples should give you the flavor of what's possible, but XRegExp has more syntax, flags, utils, 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.
7979

8080

81-
## XRegExp Unicode Base
81+
## Addons
8282

83-
First include the Unicode Base script:
83+
In browsers, 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`, which means that the addons are always available when XRegExp is installed on the server using npm.
84+
85+
86+
### XRegExp Unicode Base
87+
88+
In browsers, first include the Unicode Base script:
8489

8590
~~~ html
8691
<script src="xregexp.js"></script>
@@ -103,12 +108,12 @@ XRegExp('^\\p{Hiragana}+$').test('ひらがな'); // -> true
103108
XRegExp('^[\\p{Latin}\\p{Common}]+$').test('Über Café.'); // -> true
104109
~~~
105110

106-
XRegExp uses Unicode 6.1's Basic Multilingual Plane.
111+
XRegExp uses the Unicode 6.1 Basic Multilingual Plane.
107112

108113

109-
## XRegExp.build
114+
### XRegExp.build
110115

111-
First include the script:
116+
In browsers, first include the script:
112117

113118
~~~ html
114119
<script src="xregexp.js"></script>
@@ -135,9 +140,9 @@ Named subpatterns can be provided as strings or regex objects. A leading `^` and
135140
See also: *[Creating Grammatical Regexes Using XRegExp.build](http://blog.stevenlevithan.com/archives/grammatical-patterns-xregexp-build)*.
136141

137142

138-
## XRegExp.matchRecursive
143+
### XRegExp.matchRecursive
139144

140-
First include the script:
145+
In browsers, first include the script:
141146

142147
~~~ html
143148
<script src="xregexp.js"></script>
@@ -186,16 +191,16 @@ XRegExp.matchRecursive(str, '<', '>', 'gy');
186191
`XRegExp.matchRecursive` throws an error if it sees an unbalanced delimiter in the target string.
187192

188193

189-
## XRegExp Prototype Methods
194+
### XRegExp Prototype Methods
190195

191-
Include the script:
196+
In browsers, first include the script:
192197

193198
~~~ html
194199
<script src="xregexp.js"></script>
195200
<script src="addons/prototypes.js"></script>
196201
~~~
197202

198-
New XRegExp regexes now gain a collection of useful methods: `apply`, `call`, `forEach`, `globalize`, `xexec`, and `xtest`.
203+
New XRegExp regexes then gain a collection of useful methods: `apply`, `call`, `forEach`, `globalize`, `xexec`, and `xtest`.
199204

200205
~~~ js
201206
// To demonstrate the call method, let's first create the function we'll be using...
@@ -217,25 +222,52 @@ XRegExp.globalize(/[a-z]/i).xexec('abc');
217222
~~~
218223

219224

220-
## &c
225+
## Installation and usage
221226

222-
**Lookbehind:** A [collection of short functions](https://gist.github.com/2387872) is available that makes it easy to simulate infinite-length leading lookbehind.
227+
In browsers:
223228

229+
~~~ html
230+
<script src="xregexp-min.js"></script>
231+
~~~
224232

225-
## How to run tests on the server with npm
233+
Or, to bundle XRegExp with all of its addons:
234+
235+
~~~ html
236+
<script src="xregexp-all-min.js"></script>
237+
~~~
238+
239+
Using [npm](http://npmjs.org/):
240+
241+
~~~ bash
242+
npm install xregexp
243+
~~~
244+
245+
In [Node.js](http://nodejs.org/) and [CommonJS module](http://wiki.commonjs.org/wiki/Modules) loaders:
246+
247+
~~~ js
248+
var XRegExp = require('xregexp').XRegExp;
249+
~~~
250+
251+
252+
### Running tests on the server with npm
226253

227254
~~~ bash
228255
npm install -g qunit # needed to run the tests
229-
npm test # in the xregexp root directory
256+
npm test # in the xregexp root
230257
~~~
231258

232-
For non-npm users, just open `tests/index.html` in your browser.
259+
If XRegExp was not installed using npm, just open `tests/index.html` in your browser.
260+
261+
262+
## &c
263+
264+
**Lookbehind:** A [collection of short functions](https://gist.github.com/2387872) is available that makes it easy to simulate infinite-length leading lookbehind.
233265

234266

235267
## Changelog
236268

237-
* Historical changes: [Version history](http://xregexp.com/history/).
238-
* Planned changes: [Roadmap](https://github.com/slevithan/XRegExp/wiki/Roadmap).
269+
* Releases: [Version history](http://xregexp.com/history/).
270+
* Upcoming: [Milestones](https://github.com/slevithan/XRegExp/issues/milestones), [Roadmap](https://github.com/slevithan/XRegExp/wiki/Roadmap).
239271

240272

241273
## About

0 commit comments

Comments
 (0)