xregexp
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
XRegExp is a JavaScript library aimed at providing augmented and extensible regular expressions. It enhances the native JavaScript offers, delivering modern syntax and flags outside of what's offered by browsers. At its core, XRegExp compiles to native RegExp
objects, ensuring equivalent performance while also addressing regex cross-browser inconsistencies. Not only does it support all native ES6 regular expression syntax, but a significant number of XRegExp's features have also been adopted into new JavaScript standards, including named capturing, Unicode properties/scripts/categories, sticky matching, and more. This makes XRegExp an excellent tool for extending these features to older browsers.
To utilize XRegExp, you can include it in your JavaScript clause by installing the xregexp
npm package, or by loading it via script tag in the browser. Once installed, you can employ the XRegExp function for creating regular expressions, replacing strings, extracting data, and more. Below are some code examples demonstrating its usage:
// Create a regular expression using XRegExp
const date = XRegExp('(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})');
// Use the created regular expression to extract data
let match = XRegExp.exec('2021-02-22', date);
console.log(match.groups.year); // Outputs: '2021'
// Replace text using a created regular expression
let replacedText = XRegExp.replace('2021-02-22', date, '$<month>/$<day>/$<year>');
console.log(replacedText); // Outputs: '02/22/2021'
The examples above demonstrate basic use of XRegExp, but the library offers various other syntax, flags, methods, and options that you can employ to handle more intricate use-cases.
The comprehensive documentation for XRegExp, which includes details about all its functionalities, add-ons, and examples, can be found on its official website, xregexp.com. There, you can explore the functionalities more deeply, giving you dynamic control over your regular expressions in a way that native JavaScript doesn't allow.