Skip to content

Commit

Permalink
Tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed May 20, 2024
1 parent 85b6aba commit d90bb0a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
[
"@babel/plugin-transform-runtime",
{
"corejs": 3,
},
"corejs": 3
}
],
"add-module-exports",
"transform-xregexp",
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

[![Build Status](https://github.com/slevithan/xregexp/workflows/Node.js%20CI/badge.svg)](https://github.com/slevithan/xregexp/actions)

[<img align="left" src="https://github.com/slevithan/awesome-regex/raw/main/media/awesome-regex.svg" height="45">](https://github.com/slevithan/awesome-regex) <sub>Included in</sub><br>
<sup>[Awesome Regex](https://github.com/slevithan/awesome-regex)</sup>

XRegExp provides augmented (and extensible) JavaScript regular expressions. You get modern syntax and flags beyond what browsers support natively. XRegExp is also a regex utility belt with tools to make your grepping and parsing easier, while freeing you from regex cross-browser inconsistencies and other annoyances.

XRegExp supports all native ES6 regular expression syntax. It supports ES5+ browsers, and you can use it with Node.js or as a RequireJS module. Over the years, many of XRegExp's features have been adopted by new JavaScript standards (named capturing, Unicode properties/scripts/categories, flag `s`, sticky matching, etc.), so using XRegExp can be a way to extend these features into older browsers.
Expand Down Expand Up @@ -59,8 +62,8 @@ XRegExp.replace('2021-02-22', date, '$<month>/$<day>/$<year>');
// -> '02/22/2021'
XRegExp.replace('2021-02-22', date, (...args) => {
// Named backreferences are on the last argument
const groups = args[args.length - 1];
return `${groups.month}/${groups.day}/${groups.year}`;
const {day, month, year} = args.at(-1);
return `${month}/${day}/${year}`;
});
// -> '02/22/2021'

Expand Down
4 changes: 2 additions & 2 deletions docs/api/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -932,8 +932,8 @@ <h3>Example</h3>

// Regex search, using named backreferences in replacement function
XRegExp.replace('John Smith', name, (...args) => {
const groups = args[args.length - 1];
return `${groups.last}, ${groups.first}`;
const {first, last} = args.at(-1);
return `${last}, ${first}`;
});
// -> 'Smith, John'

Expand Down

0 comments on commit d90bb0a

Please sign in to comment.