diff --git a/README.md b/README.md index 45b5f4c..26cb80d 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,8 @@ With the Regex+ library, JavaScript steps up as one of the best regex flavors al Table of contents - [Features](#-features) -- [Examples](#-examples) - [Install and use](#️-install-and-use) +- [Examples](#-examples) - [Context](#-context) - [Extended regex syntax](#-extended-regex-syntax) - [Atomic groups](#atomic-groups) @@ -65,6 +65,44 @@ With the Regex+ library, JavaScript steps up as one of the best regex flavors al - Interpolated strings have their special characters escaped. - Interpolated regexes locally preserve the meaning of their own flags (or their absense), and their numbered backreferences are adjusted to work within the overall pattern. +## 🕹️ Install and use + +```sh +npm install regex +``` + +```js +import {regex} from 'regex'; + +// Works with all string/regexp methods since it returns a native regexp +const str = 'abc'; +regex`\w`.test(str); // → true +str.match(regex('g')`\w`); // → ['a', 'b', 'c'] +``` + +
+ In browsers + +ESM: + +```html + +``` + +Using a global name: + +```html + + +``` +
+ ## 🪧 Examples ```js @@ -105,41 +143,7 @@ regex`^ (?.) ${double} ${double} $`; // → /^(?.)(.)\2(.)\3$/v ``` -## 🕹️ Install and use - -```sh -npm install regex -``` - -```js -import {regex} from 'regex'; - -// Works with all string/regexp methods since it returns a native regexp -const str = 'abc'; -regex`.`.test(str); -str.match(regex('g')`.`); -``` - -In browsers: - -```html - -``` - -
- Using a global name (no import) - -```html - - -``` -
+See also this example of using a subroutine definition group to [refactor an IP address regex for readability](https://x.com/slevithan/status/1828112006353953055). ## ❓ Context @@ -360,8 +364,6 @@ console.log(match.groups); } */ ``` -See also this example of using a subroutine definition group to [refactor an IP address regex for readability](https://x.com/slevithan/status/1828112006353953055). - > [!NOTE] > Subroutine definition groups are based on the feature in PCRE and Perl. However, `regex` supports a stricter version since it limits their placement, quantity, and the top-level syntax that can be used within them.