-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ Create readable Regular Expressions with concise and flexible syntax. | |
- [Installation](#installation) | ||
- [Using a package manager](#using-a-package-manager) | ||
- [Using a CDN](#using-a-cdn) | ||
- [Quick Example](#quick-example) | ||
- [Features](#features) | ||
- [Readability](#readability) | ||
- [Flexibility and Conciseness](#flexibility-and-conciseness) | ||
|
@@ -63,6 +64,58 @@ Import readable-regexp via a script tag in your HTML file, then access the `read | |
const { oneOrMore, exactly } = readableRegExp; | ||
``` | ||
|
||
## Quick Example | ||
|
||
This is an email RegExp: | ||
|
||
```js | ||
/^([^<>()[\]\\.,;:@"\s]+(?:\.[^<>()[\]\\.,;:@"\s]+)*|".+")@(\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]|(?:[a-zA-Z0-9\-]+\.)+[a-zA-Z]{2,})$/ | ||
``` | ||
|
||
And this is the same expression written in readable RegExp: | ||
|
||
```js | ||
const allowedChar = notCharIn`<>()[]\\\\``.,;:@"`(whitespace); | ||
const email = lineStart | ||
.capture.oneOf | ||
( // username | ||
oneOrMore.match(allowedChar) | ||
.zeroOrMore( | ||
exactly`.` | ||
.oneOrMore.match(allowedChar) | ||
) | ||
) | ||
( // quoted string | ||
exactly`"` | ||
.oneOrMore.char | ||
.exactly`"` | ||
) | ||
.exactly`@` | ||
.capture.oneOf | ||
( // IPv4 address | ||
exactly`[` | ||
.repeat(1, 3).digit | ||
.exactly`.` | ||
.repeat(1, 3).digit | ||
.exactly`.` | ||
.repeat(1, 3).digit | ||
.exactly`.` | ||
.repeat(1, 3).digit | ||
.exactly`]` | ||
) | ||
( // domain name | ||
oneOrMore( | ||
oneOrMore.charIn`a-z``A-Z``0-9``-` | ||
.exactly`.` | ||
) | ||
.atLeast(2).charIn`a-z``A-Z` | ||
) | ||
.lineEnd | ||
.toRegExp(); | ||
|
||
email.test("[email protected]"); // true | ||
``` | ||
|
||
## Features | ||
|
||
### Readability | ||
|