re.js
© 2016, Onur Yıldırım (@onury). MIT License.
RegExp
API for Humans!
- Friendly API! e.g.
re(pattern).each(input, callback)
- Universal module (Browser/Node/CommonJS/AMD)
- Small size. Only 1.5 KB minified, gzipped.
- Well documented.
Installation
Install via NPM:
npm i re.js
Install via Bower:
bower install re.js
Usage
For all the features and details, please read the API reference.
const re = ;
.each()
var input = 'Peter Piper picked a peck of pickled peppers.'; ;
Note that above example does not have a g
flag (for global) in the RegExp
. But logically; since you're calling each()
it should search for all. So re
automatically fixes it for you.
.eachRight()
Iterate from last match to first.
;
.map()
var mapped = ;console;// —> ["Peter", "Piper", "picked", "peck", "pickled", "peppers"]
.all()
allinput;// —> [Array, Array, Array, Array, Array, Array]
.match()
;// —> ["Peter", "Piper", "picked", "peck", "pickled", "peppers"]
.exec().next()
next { console; // —> 0: "Peter" } next { console; // —> 1: "Piper" }
.test()
for convenience...
; // —> true
Match Indices
0; // —> "Peter"; // —> 0index; // —> 0 ; // —> null; // —> -1index; // —> Error 0; // —> "peppers"lastIndexinput; // —> 37index; // —> 37 0; // —> "picked" ; // —> [ 0, 6, 12, 21, 29, 37 ]
Documentation
Change Log
-
v1.1.0
.eachRight()
callback parameterindex
is now reversed. (last iteration index will be0
.)- Added
.eachInverse()
method for iterating over non-matched blocks. #experimental - Added extra argument to callbacks for convenience:
charIndex
(same asmatches.index
).
-
v1.0.0
- Initial release.
License
MIT.