Expand description
§to-regex-range — a regex that matches an integer range
Generate a compact regular-expression source string matching every integer in a
range: (1, 99) becomes [1-9]|[1-9][0-9]. A faithful Rust port of the
to-regex-range npm package (a
micromatch building block). Zero dependencies and #![no_std].
use to_regex_range::{to_regex_range, to_regex_range_with_options, Options};
assert_eq!(to_regex_range(1, 5), "[1-5]");
assert_eq!(to_regex_range(1, 99), "(?:[1-9]|[1-9][0-9])");
assert_eq!(to_regex_range(-10, -1), "(?:-[1-9]|-10)");
let opts = Options::default().shorthand(true);
assert_eq!(to_regex_range_with_options(1, 99, &opts), "(?:[1-9]|[1-9]\\d)");The result is a regex source (no delimiters); wrap it in your regex engine of
choice. Operates on integer ranges; zero-padded ranges (001..100) are out of
scope.
Structs§
- Options
- Options controlling the generated regex. Construct with
Options::defaultand the builder methods.
Functions§
- to_
regex_ range - Generate a regex source matching every integer from
mintomax(inclusive), using the defaultOptions. - to_
regex_ range_ with_ options - Generate a regex source matching every integer from
mintomax(inclusive).