Version 2.0.0 is a breaking upgrade. For compatibility with XRegExp 1.x.x, include backcompat.js after loading xregexp.js.
XRegExp.install with options 'natives' and 'extensibility' (accepted as an object or string). Allows you to selectively add these optional features on demand. Use the shorthand 'all' to install all optional features.
'natives' overrides the native methods RegExp.prototype.exec/test and String.prototype.match/replace/split with fixed/extended versions that support named backreferences and fix numerous cross-browser bugs.'extensibility' enables XRegExp.addToken, which is used by addons to extend XRegExp syntax and flags.XRegExp.uninstall with options 'natives' and 'extensibility' (accepted as an object or string). Use the shorthand 'all' to uninstall all optional features.XRegExp.isInstalled as a way of checking whether specific optional features are installed.n (also supported via a leading (?n)), based on .NET's ExplicitCapture/(?n) flag. When regexes are built with flag n, only explicitly named groups of the form (?<name>…) capture a value. This makes unnamed (…) parentheses act as noncapturing groups without the syntactic clumsiness of (?:…).XRegExp.union, for safely merging strings and regexes into a single pattern. (Comes from Ruby, but one-ups Ruby by officially supporting backreference rewriting for merged patterns.)XRegExp.replace. Like the fixed String.prototype.replace (which is available only after running XRegExp.install('natives')), this supports named backreferences in replacement strings and functions, and includes various browser fixes compared to the native replace. XRegExp.replace additionally includes an optional fourth scope argument (accepts values 'one' [default] and 'all') that overrides /g when explicitly specified and allows global replacements with nonregex searches.XRegExp.split as an alias of the fixed String.prototype.split (which is available only after running XRegExp.install('natives')).XRegExp.test. Like the fixed RegExp.prototype.test (which is available only after running XRegExp.install('natives')), this fixes browser bugs for the setting of lastIndex. It additionally includes optional pos and sticky arguments, and doesn't use lastIndex for its own handling of regexes with /g.XRegExp.forEach return the provided context object (allows simplified usage).XRegExp as exports.XRegExp for CommonJS enviroments.$0 (not followed by 1-9) and $00 in replacement text to insert the full match, as alternatives to $& and ${0} (which continue to work). IE (tested IE 9) already supports $0 natively.XRegExp.iterate as XRegExp.forEach.XRegExp.execAt as XRegExp.exec.XRegExp.copyAsGlobal as XRegExp.globalize.XRegExp.freezeTokens (replaced by XRegExp.uninstall).RegExp.prototype.apply/call (replaced by XRegExp.prototype.apply/call in the XRegExp Prototype Methods addon).SyntaxError on any use of octals (except \0 not followed by 0-9) or as-yet-undefined backreferences in an XRegExp pattern, to avoid having the sky fall on your head when you do so. (ES3 removed octals except \0 from regex syntax, but browsers still support them.)SyntaxError (e.g., \z throws rather than matching 'z'), unless they are overridden by XRegExp addons. Make the same apply for \u not followed by four hex digits, \x not followed by two hex digits, and \c not followed by A-Z or a-z. This makes letter escapes safe for future use with new functionality.$10 in replacement text throw a SyntaxError unless there are at least 10 capturing groups. Use e.g. ${1}0 for backreference 1 followed by a literal 0.$ in replacement text throw a SyntaxError when followed by anything that does not make a valid replacement token (e.g., $? or ${undefinedName}), rather than being handled as literal text.XRegExp.addToken to accept the optional scope and trigger arguments via an options object.XRegExp.INSIDE_CLASS/OUTSIDE_CLASS. Change token scopes to 'default', 'class', and 'all'.XRegExp(regexp) and XRegExp.globalize copy regexes using the RegExp constructor rather than XRegExp if the provided regex was not built by XRegExp (i.e., don't look for special tokens).SyntaxError when a regex is compiled with an invalid/unregistered flag. Also applies to flags set via a mode modifier.customFlags option to the XRegExp.addToken options object, which registers any custom flags used by the token. This avoids throwing a SyntaxError when the new flag or flags are used.SyntaxError when duplicate flags are provided to the XRegExp constructor, as recent browsers do for RegExp.XRegExp.exec's fourth argument (sticky) officially support the string 'sticky' as a way to enable sticky mode, as a more readable alternative to Boolean true. (Already works in previous versions since nonempty strings are truthy.)XRegExp(), equivalent to XRegExp('') (following RegExp).XRegExp.prototype properties to new XRegExp regex instances. (This didn't automatically work before because of JavaScript's rules about constructors that return nonprimitive values.) RegExp objects copied via XRegExp(regexp) or XRegExp.globalize will also automatically get these properties.XRegExp('(?<n>a)(?<n>b)\\k<n>').test('abb') == true, result.n is 'b', etc.)SyntaxError if a bare integer is used as a capture name (e.g., (?<1>…)), to avoid incorrect lookups since named backreferences are added as properties of match arrays.\k<1> (where 1 is any integer) reference capturing group number 1 (even if the first capturing group has a defined name). Previously, it could only reference a capturing group explicitly named 1.\k<…> with a number or name that references an as-yet-undefined group an error. Previously, \k<name>(?<name>…) was not an error but did not work as expected.'undefined'.sticky argument of XRegExp.exec override flag y when explicitly specified as false.split when it's provided a very large number as its limit argument (e.g., Infinity or Math.pow(2,32)+1), converting to a very small number per the spec rules.backcompat.js.Changes since Unicode Base 0.6.0, Categories 1.1.0, Scripts 1.1.0, and Blocks 1.1.0:
\p{Letter} instead of \p{L}.[^\p{L}\p{N}] instead of [\P{L}\P{N}].Changes since XRegExp.matchRecursive 0.1.1:
m when using escapeChar (previously threw a descriptive error).left and right delimiters when using escapeChar.Alphabetic, Uppercase, Lowercase, White_Space, Noncharacter_Code_Point, Default_Ignorable_Code_Point, Any, ASCII, and Assigned.apply, call, forEach, globalize, xexec, and xtest.This is a bug fix release that addresses a number of issues reported by users and teased out via the new test suite.
RegExp.prototype.exec, RegExp.prototype.test, String.prototype.match, and String.prototype.replace ignore the lastIndex property of nonglobal regexes, even in browsers that get this wrong natively.XRegExp.execAt and XRegExp.iterate update the lastIndex property of global regexes (even though they don't use it) based on the spec for RegExp.prototype.exec and String.prototype.replace.callback funtion with XRegExp.iterate.RegExp.prototype.exec no longer throws an error in IE when it is simultaneously provided a nonstring argument and called on a regex with a capturing group that matches an empty string.undefined or no replacement value is provided to String.prototype.replace, it is type converted to the string 'undefined'.String.prototype.replace replacement functions (the full original string) is now a string primitive rather than a String object in IE8 and earlier.RegExps provided to String.prototype.replace as the replacement value in old browsers that report typeof /regex/ as 'function'.This release significantly changes the API for XRegExp's suite of functions. A backward compatibility layer for XRegExp 1.0.0–1.2.0 is available at the end of the script (uncomment to enable).
XRegExp.execAt function.XRegExp.matchChain can now pass forward and return named or numbered backreferences as match values.(?imsx) mode modifier supported at the start of patterns only.RegExp.prototype.addFlags and added XRegExp.copyAsGlobal to take over its common use case.RegExp.prototype.forEachExec and replaced it with XRegExp.iterate.XRegExp.matchWithinChain to XRegExp.matchChain.XRegExp.matchChain's detailMode option.RegExp.prototype.validate since it had no strong use cases.XRegExp.addToken adds /y to token regexes when supported natively, for improved performance.XRegExp.addToken after XRegExp.freezeTokens throws a descriptive error.XRegExp calls to throw.RegExp.prototype.execAll since it is trivial to implement using RegExp.prototype.forEachExec.window, which allows it to be used in nonbrowser contexts.'undefined' was inserted into the returned string in IE.lastIndex property of regexes created with the /g flag is not always reset to zero after running String.prototype.replace or String.prototype.match is now fixed automatically.lastIndex property of a regex is not updated during String.prototype.replace iterations (visible within replacement functions) is now fixed automatically.String.prototype.split and String.prototype.replace now consistently work with non-string context (this).[] caused incorrect results in some edge cases in Firefox only, due to a Firefox bug in handling empty negative lookahead.$nn backreferences in replacement text.String.prototype.replace were also fixed. Mostly, these were edge-case issues introduced in XRegExp 1.0.0.XRegExp.addToken function.XRegExp.freezeTokens function.XRegExp.isRegExp function.XRegExp.matchWithinChain function.RegExp.prototype.validate method.RegExp.prototype.forEachExec method.RegExp.prototype.execAll method.${…} replacement text token now supports numbered backreferences (and thereby offers an otherwise-unavailable way to separate backreferences from literal numbers), in addition to named backreferences. This follows prior art in .NET, etc.lastIndex properties after zero-length matches are found by RegExp.prototype.test (already performed for RegExp.prototype.exec and String.prototype.match).XRegExp.version property.XRegExp.matchRecursive function. It's now a standalone plugin.XRegExp.addPlugin, which was hard-coded to work with the Unicode plugin only. If you use this plugin, download an updated version (v0.3.0 or higher).limit argument of String.prototype.split is now followed consistently.$n tokens in replacement text are now limited to two digits, even when there are more than 99 capturing groups in your regex. Use ${nnn} for three or more digit backreferences.String.prototype.split, if the last match of the separator within the subject string ended at the end of the string, and the separator was capable of matching an empty string (e.g. /a?/), a trailing empty string value was not appended to the result array even when the separator did not match an empty string in that last case. This followed Firefox's native handling, but not the spec (which at least Opera follows correctly).XRegExp.matchRecursive could not return more than one match when the sticky (y) and global (g) modifiers were combined without using valueNames.RegExp.prototype.addFlags did not preserve previously applied, non-native modifiers (v0.5.0 only).XRegExp.matchRecursive function.XRegExp.escape function.XRegExp.cache function.RegExp.prototype.call/apply methods.(?#…).String.prototype.split method.RegExp.prototype.exec and String.prototype.match return values for nonparticipating capturing groups.lastIndex properties after zero-length matches are returned by RegExp.prototype.exec and String.prototype.match.(<name>…) to (?<name>…), which is the standard syntax in .NET, Perl, and PCRE, and under consideration for ES4.k modifier.y) and extended (x) modifiers. Sticky mode will be in JS1.8; both are proposed for ES4.RegExp object to the XRegExp constructor now returns a new copy, like the native RegExp constructor.XRegExp.overrideNative. The RegExp constructor cannot be overriden in JS1.8 or current ES4 proposals.k modifier.
(<name>…)\k<name>${name}result.name, or arguments[0].name in replacement functionsRegExp.prototype.addFlags method.XRE global object. XRE.overrideNative is now XRegExp.overrideNative.x modifier now ignores whitespace between a regex token and its quantifier, rather than collapsing it to (?:).s, aka singleline) modifier.x, aka extended) modifier.] in character classes.XRE.overrideNative function, which applies these regex extensions to the RegExp constructor.◊