regex-macro
This crate contains a little macro to generate a lazy
Regex
and remove some boilerplate when
compiling regex expressions.
Usage
Since it is an anti-pattern to compile the same regular expression in a loop
this means for most regex expressions you need to store them in a
LazyLock
in a static. But this can get a bit tiresome with many regex
expressions. This crate provides a regex!
macro that will store the
compiled regex in a global static and return a reference to it.
Before
use LazyLock;
use Regex;
// only compiled once, by storing in a static
static HEX_PATTERN: = new;
for item in my_iter
After
use regex;
for item in my_iter
Isn’t that much nicer?
License
This project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See LICENSE-APACHE and LICENSE-MIT for details.