Skip to content

Instantly share code, notes, and snippets.

View allenanie's full-sized avatar
🏔️
Gradient ascending

Allen Nie allenanie

🏔️
Gradient ascending
View GitHub Profile
@slevithan
slevithan / xregexp-lookbehind.js
Created April 14, 2012 20:48
Simulating lookbehind in JavaScript
// Simulating infinite-length leading lookbehind in JavaScript. Uses XRegExp
// and XRegExp.matchRecursive. Any regex pattern can be used within lookbehind,
// including nested groups. Captures within lookbehind are not included in
// match results. Lazy repetition in lookbehind may lead to unexpected results.
(function (XRegExp) {
function preparePattern(pattern, flags) {
var lbOpen, lbEndPos, lbInner;
flags = flags || "";