Ever wished for a better way to write regular expressions? If so, today is the day this dream comes true as I present to you super-expressive!
Install the dependency, e.g. with:
deno add npm:super-expressive
Create a file, e.g. main.ts
:
import SuperExpressive from "npm:super-expressive";
const regExp = SuperExpressive()
.caseInsensitive
.allowMultipleMatches
.string("<strong>Find me!</strong>")
.toRegex();
console.log(
"Do you think you would be able to <strong>Find me!</strong>? Or Find me! So go on and <strong>Find me!</strong>".replace(
regExp,
"FOUND!"
)
);
And running the script should result in:
deno run -A ./main.ts
Do you think you would be able to FOUND!? Or Find me! So go on and FOUND!
What do you think? Is it a nicer way to write RegExps or should we still learn how to do it manually?
Liked the content and would love to have more of it all year long?
Top comments (0)