|
|
|
|
|
by truth_seeker
295 days ago
|
|
Magic-RegExp aims to create a compiled away, type-safe, readable RegEx alternative that makes the process a lot easier.
https://blog.logrocket.com/understanding-magic-regexp-regexp... example from blog: import {
createRegExp,
exactly,
wordChar,
oneOrMore,
anyOf,
} from "magic-regexp"; const regExp = createRegExp( exactly("http")
.and(exactly("s").optionally())
.and("://")
.optionally()
.and(exactly("www.").optionally())
.and(oneOrMore(wordChar))
.and(exactly("."))
.and(anyOf("com", "org", "io")),
["g", "m", "i"]
);console.log(regExp); /(https?:\/\/)?(www\.)?\w+\.(com|org|io)/gmi |
|